mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 11:20:45 +00:00
working
This commit is contained in:
@@ -7,7 +7,6 @@ import {Settings} from "../core/Settings";
|
||||
import {GameRenderer} from "./GameRenderer";
|
||||
import {InputHandler, MouseUpEvent, ZoomEvent, DragEvent, MouseDownEvent} from "./InputHandler"
|
||||
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.input.initialize()
|
||||
// this.executor.spawnBots(500)
|
||||
this.executor.spawnBots(500)
|
||||
|
||||
|
||||
setInterval(() => this.tick(), 10);
|
||||
|
||||
@@ -85,6 +85,8 @@ export interface MutableBoat extends Boat {
|
||||
export interface TerraNullius {
|
||||
ownsTile(cell: Cell): boolean
|
||||
isPlayer(): false
|
||||
borderTilesWith(other: Player): ReadonlySet<Tile>
|
||||
sharesBorderWith(other: Player): boolean
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
public _boats: BoatImpl[] = []
|
||||
@@ -192,6 +203,21 @@ class TerraNulliusImpl implements TerraNullius {
|
||||
}
|
||||
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 {
|
||||
|
||||
@@ -72,14 +72,11 @@ export class AttackExecution implements Execution {
|
||||
}
|
||||
|
||||
private calculateToConquer() {
|
||||
const border = this.owner().borderTilesWith(this.target)
|
||||
const enemyBorder: Set<Tile> = new Set()
|
||||
for (const b of border) {
|
||||
b.neighbors()
|
||||
.filter(t => t.terrain() == TerrainTypes.Land)
|
||||
.filter(t => t.owner() == this.target)
|
||||
.forEach(t => enemyBorder.add(t))
|
||||
}
|
||||
// console.profile('calc_to_conquer')
|
||||
|
||||
const enemyBorder = this.target.borderTilesWith(this._owner)
|
||||
|
||||
|
||||
|
||||
// let closestTile: Tile;
|
||||
// let closestDist: number = Number.POSITIVE_INFINITY;
|
||||
@@ -108,27 +105,37 @@ export class AttackExecution implements Execution {
|
||||
// }
|
||||
this.toConquer.clear()
|
||||
|
||||
let tiles = Array.from(enemyBorder)
|
||||
|
||||
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))
|
||||
}
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
this.toConquer.add(new TileContainer(tile, - numOwnedByMe + this.random.nextInt(0, 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 {
|
||||
|
||||
Reference in New Issue
Block a user