mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-30 15:32:11 +00:00
better UX for boats
This commit is contained in:
@@ -43,6 +43,7 @@ export class PlayerInfo {
|
||||
export interface Tile {
|
||||
isLand(): boolean
|
||||
isShore(): boolean
|
||||
isOceanShore(): boolean
|
||||
isWater(): boolean
|
||||
isShorelineWater(): boolean
|
||||
isOcean(): boolean
|
||||
|
||||
@@ -35,6 +35,10 @@ class TileImpl implements Tile {
|
||||
isShore(): boolean {
|
||||
return this.isLand() && this._terrain.shoreline
|
||||
}
|
||||
isOceanShore(): boolean {
|
||||
return this.isShore() && this.neighbors().find(t => t.isOcean()) != null
|
||||
}
|
||||
|
||||
isShorelineWater(): boolean {
|
||||
return this.isWater() && this._terrain.shoreline
|
||||
}
|
||||
|
||||
+11
-2
@@ -1,3 +1,4 @@
|
||||
import {functional} from "typia";
|
||||
import {Cell, Tile} from "./Game";
|
||||
|
||||
export function manhattanDist(c1: Cell, c2: Cell): number {
|
||||
@@ -8,7 +9,15 @@ export function within(value: number, min: number, max: number): number {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
export function bfs(tile: Tile, dist: number): Set<Tile> {
|
||||
export function dist(dist: number): (root: Tile, tile: Tile) => boolean {
|
||||
return (root: Tile, n: Tile) => manhattanDist(root.cell(), n.cell()) <= dist;
|
||||
}
|
||||
|
||||
export function and(x: (root: Tile, tile: Tile) => boolean, y: (root: Tile, tile: Tile) => boolean): (root: Tile, tile: Tile) => boolean {
|
||||
return (root: Tile, tile: Tile) => x(root, tile) && y(root, tile)
|
||||
}
|
||||
|
||||
export function bfs(tile: Tile, filter: (root: Tile, tile: Tile) => boolean): Set<Tile> {
|
||||
const seen = new Set<Tile>
|
||||
const q: Tile[] = []
|
||||
q.push(tile)
|
||||
@@ -16,7 +25,7 @@ export function bfs(tile: Tile, dist: number): Set<Tile> {
|
||||
const curr = q.pop()
|
||||
seen.add(curr)
|
||||
for (const n of curr.neighbors()) {
|
||||
if (!seen.has(n) && manhattanDist(tile.cell(), n.cell()) <= dist) {
|
||||
if (!seen.has(n) && filter(tile, n)) {
|
||||
q.push(n)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import {DefaultConfig, DefaultPlayerConfig, defaultPlayerConfig} from "./Default
|
||||
|
||||
export const devConfig = new class extends DefaultConfig {
|
||||
numSpawnPhaseTurns(): number {
|
||||
return 40
|
||||
return 60
|
||||
}
|
||||
gameCreationRate(): number {
|
||||
return 3 * 1000
|
||||
@@ -19,7 +19,7 @@ export const devConfig = new class extends DefaultConfig {
|
||||
return devPlayerConfig
|
||||
}
|
||||
numBots(): number {
|
||||
return 250
|
||||
return 50
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ export class AStar {
|
||||
compute(iterations: number): boolean {
|
||||
if (this.completed) return true;
|
||||
|
||||
while (!this.openSet.size()) {
|
||||
while (!this.openSet.isEmpty()) {
|
||||
iterations--
|
||||
this.current = this.openSet.dequeue()!.tile;
|
||||
if (iterations <= 0) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Cell, Game} from "../Game";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
import {SpawnIntent} from "../Schemas";
|
||||
import {bfs} from "../Util";
|
||||
import {bfs, dist as dist} from "../Util";
|
||||
import {getSpawnCells} from "./Util";
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ export class BotSpawner {
|
||||
spawnBot(botName: string): SpawnIntent {
|
||||
const rand = this.random.nextInt(0, this.numFreeTiles);
|
||||
const spawn = this.freeTiles[rand];
|
||||
bfs(this.gs.tile(spawn), 50).forEach(t => this.removeCell(t.cell()))
|
||||
bfs(this.gs.tile(spawn), dist(50)).forEach(t => this.removeCell(t.cell()))
|
||||
const spawnIntent: SpawnIntent = {
|
||||
type: 'spawn',
|
||||
name: botName,
|
||||
|
||||
Reference in New Issue
Block a user