mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 09:14:09 +00:00
working
This commit is contained in:
@@ -7,7 +7,6 @@ import {Settings} from "../core/Settings";
|
|||||||
import {GameRenderer} from "./GameRenderer";
|
import {GameRenderer} from "./GameRenderer";
|
||||||
import {InputHandler, MouseUpEvent, ZoomEvent, DragEvent, MouseDownEvent} from "./InputHandler"
|
import {InputHandler, MouseUpEvent, ZoomEvent, DragEvent, MouseDownEvent} from "./InputHandler"
|
||||||
import {ClientIntentMessageSchema, ClientJoinMessageSchema, ClientMessageSchema, ServerMessage, ServerMessageSchema, ServerSyncMessage, Turn} from "../core/Schemas";
|
import {ClientIntentMessageSchema, ClientJoinMessageSchema, ClientMessageSchema, ServerMessage, ServerMessageSchema, ServerSyncMessage, Turn} from "../core/Schemas";
|
||||||
import {AttackIntent, Intent, SpawnIntent} from "../core/Schemas";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +95,7 @@ export class ClientGame {
|
|||||||
|
|
||||||
this.renderer.initialize()
|
this.renderer.initialize()
|
||||||
this.input.initialize()
|
this.input.initialize()
|
||||||
// this.executor.spawnBots(500)
|
this.executor.spawnBots(500)
|
||||||
|
|
||||||
|
|
||||||
setInterval(() => this.tick(), 10);
|
setInterval(() => this.tick(), 10);
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ export interface MutableBoat extends Boat {
|
|||||||
export interface TerraNullius {
|
export interface TerraNullius {
|
||||||
ownsTile(cell: Cell): boolean
|
ownsTile(cell: Cell): boolean
|
||||||
isPlayer(): false
|
isPlayer(): false
|
||||||
|
borderTilesWith(other: Player): ReadonlySet<Tile>
|
||||||
|
sharesBorderWith(other: Player): boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Player {
|
export interface Player {
|
||||||
|
|||||||
@@ -67,6 +67,17 @@ export class BoatImpl implements MutableBoat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Border {
|
||||||
|
borderWith: Map<Player | TerraNullius, Set<Tile>> = new Map()
|
||||||
|
|
||||||
|
sharesBorderWith(other: Player | TerraNullius): boolean {
|
||||||
|
if (!this.borderWith.has(other)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return this.borderWith.get(other).size > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class PlayerImpl implements MutablePlayer {
|
export class PlayerImpl implements MutablePlayer {
|
||||||
|
|
||||||
public _boats: BoatImpl[] = []
|
public _boats: BoatImpl[] = []
|
||||||
@@ -192,6 +203,21 @@ class TerraNulliusImpl implements TerraNullius {
|
|||||||
}
|
}
|
||||||
isPlayer(): false {return false as const}
|
isPlayer(): false {return false as const}
|
||||||
|
|
||||||
|
borderTilesWith(other: Player): ReadonlySet<Tile> {
|
||||||
|
const border = new Set<Tile>()
|
||||||
|
for (const enemyBorder of other.borderTilesWith(this)) {
|
||||||
|
for (const neighbor of enemyBorder.neighbors()) {
|
||||||
|
if (neighbor.terrain() == TerrainTypes.Land && neighbor.owner() == this) {
|
||||||
|
border.add(neighbor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return border
|
||||||
|
}
|
||||||
|
|
||||||
|
sharesBorderWith(other: Player): boolean {
|
||||||
|
return other.sharesBorderWith(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TerrainMapImpl implements TerrainMap {
|
export class TerrainMapImpl implements TerrainMap {
|
||||||
|
|||||||
@@ -72,14 +72,11 @@ export class AttackExecution implements Execution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private calculateToConquer() {
|
private calculateToConquer() {
|
||||||
const border = this.owner().borderTilesWith(this.target)
|
// console.profile('calc_to_conquer')
|
||||||
const enemyBorder: Set<Tile> = new Set()
|
|
||||||
for (const b of border) {
|
const enemyBorder = this.target.borderTilesWith(this._owner)
|
||||||
b.neighbors()
|
|
||||||
.filter(t => t.terrain() == TerrainTypes.Land)
|
|
||||||
.filter(t => t.owner() == this.target)
|
|
||||||
.forEach(t => enemyBorder.add(t))
|
|
||||||
}
|
|
||||||
|
|
||||||
// let closestTile: Tile;
|
// let closestTile: Tile;
|
||||||
// let closestDist: number = Number.POSITIVE_INFINITY;
|
// let closestDist: number = Number.POSITIVE_INFINITY;
|
||||||
@@ -108,27 +105,37 @@ export class AttackExecution implements Execution {
|
|||||||
// }
|
// }
|
||||||
this.toConquer.clear()
|
this.toConquer.clear()
|
||||||
|
|
||||||
let tiles = Array.from(enemyBorder)
|
|
||||||
|
|
||||||
if (this.targetCell != null) {
|
if (this.targetCell != null) {
|
||||||
|
let tiles = Array.from(enemyBorder)
|
||||||
tiles = tiles.slice().sort((a, b) => manhattanDist(a.cell(), this.targetCell) - manhattanDist(b.cell(), this.targetCell))
|
tiles = tiles.slice().sort((a, b) => manhattanDist(a.cell(), this.targetCell) - manhattanDist(b.cell(), this.targetCell))
|
||||||
}
|
for (let i = 0; i < tiles.length; i++) {
|
||||||
|
const numOwnedByMe = tiles[i].neighbors()
|
||||||
|
.filter(t => t.terrain() == TerrainTypes.Land)
|
||||||
|
.filter(t => t.owner() == this._owner)
|
||||||
|
.length
|
||||||
|
|
||||||
|
let distModifer = 0
|
||||||
|
if (this.targetCell != null) {
|
||||||
|
distModifer = i / tiles.length * 2
|
||||||
|
}
|
||||||
|
this.toConquer.add(new TileContainer(tiles[i], distModifer - numOwnedByMe + this.random.nextInt(0, 2)))
|
||||||
|
// this.toConquer.add(new TileContainer(tiles[i], i))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const tile of enemyBorder) {
|
||||||
|
const numOwnedByMe = tile.neighbors()
|
||||||
|
.filter(t => t.terrain() == TerrainTypes.Land)
|
||||||
|
.filter(t => t.owner() == this._owner)
|
||||||
|
.length
|
||||||
|
|
||||||
for (let i = 0; i < tiles.length; i++) {
|
this.toConquer.add(new TileContainer(tile, - numOwnedByMe + this.random.nextInt(0, 2)))
|
||||||
const numOwnedByMe = tiles[i].neighbors()
|
|
||||||
.filter(t => t.terrain() == TerrainTypes.Land)
|
|
||||||
.filter(t => t.owner() == this._owner)
|
|
||||||
.length
|
|
||||||
|
|
||||||
let distModifer = 0
|
|
||||||
if (this.targetCell != null) {
|
|
||||||
distModifer = i / tiles.length * 2
|
|
||||||
}
|
}
|
||||||
this.toConquer.add(new TileContainer(tiles[i], distModifer - numOwnedByMe + this.random.nextInt(0, 2)))
|
|
||||||
// this.toConquer.add(new TileContainer(tiles[i], i))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.profileEnd('calc_to_conquer')
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
owner(): MutablePlayer {
|
owner(): MutablePlayer {
|
||||||
|
|||||||
Reference in New Issue
Block a user