private string OneBestMove(GameState gameState, IPathfinder pathfinder) { string murderDirection = murderAlgo(gameState); if (!string.IsNullOrEmpty(murderDirection)) { Console.Out.WriteLine("WARWARWAR"); return(murderDirection); } // If we suddenly lost a lot of life, maybe we should reconsider. if (heroLife.HasValue && heroLife.Value >= (gameState.myHero.life + 20)) { Console.WriteLine("EvenBestChoice: LOW ON LIFE! Maybe we were attacked?"); target = null; } heroLife = gameState.myHero.life; // If we suddenly moved a lot, maybe we should reconsider. if (heroPos != null && Pos.DistanceBetween(heroPos, gameState.myHero.pos) >= 2) { Console.WriteLine("EvenBestChoice: TELEPORTED! Maybe we were killed?"); target = null; } heroPos = gameState.myHero.pos; Tuple <PathData, TargetInfo> pathDataAndTarget = null; if (target != null) { Console.WriteLine("EvenBestChoice: Current target: ({0},{1}) [tile {2}]", target.pos.x, target.pos.y, target.tile); pathDataAndTarget = Tuple.Create(pathfinder.pathTo(target.pos, gameState.myHero.pos, gameState.board, SPIKE_COST), target); } else { // Seek mine if possible, otherwise seek a tavern if (gameState.myHero.life >= 35) { pathDataAndTarget = SeekMine(gameState, pathfinder); } if (pathDataAndTarget == null || pathDataAndTarget.Item1.lostHealth >= gameState.myHero.life) { pathDataAndTarget = SeekTavern(gameState, pathfinder); } } // If this is the last move, release target unless it's a tavern and we're < 90 life if (target != null && pathDataAndTarget != null && pathDataAndTarget.Item1.nextDirection != Direction.Stay && Pos.DistanceBetween(target.pos, gameState.myHero.pos) <= 1 && (target.tile != Tile.TAVERN || gameState.myHero.life >= 90)) { Console.WriteLine("EvenBestChoice: Reached destination ({0},{1}) [{2}], releasing target", target.pos.x, target.pos.y, target.tile); target = null; } string nextDirection = pathDataAndTarget != null ? pathDataAndTarget.Item1.nextDirection : null; return(!String.IsNullOrEmpty(nextDirection) ? nextDirection : Direction.Stay); }
private String murderAlgo(GameState gameState) { int size = gameState.board.Length - 1; Pos myPos = gameState.myHero.pos; foreach (Hero hero in gameState.heroes) { if (hero.pos.x < size && gameState.board[hero.pos.x + 1][hero.pos.y] == Tile.TAVERN) { continue; } if (hero.pos.y < size && gameState.board[hero.pos.x][hero.pos.y + 1] == Tile.TAVERN) { continue; } if (hero.pos.x > 0 && gameState.board[hero.pos.x - 1][hero.pos.y] == Tile.TAVERN) { continue; } if (hero.pos.y > 0 && gameState.board[hero.pos.x][hero.pos.y - 1] == Tile.TAVERN) { continue; } if (Pos.DistanceBetween(hero.pos, hero.spawnPos) == 0) { continue; } if (hero.life < gameState.myHero.life) { if (Math.Abs(myPos.x - hero.pos.x) + Math.Abs(myPos.y - hero.pos.y) == 2) { if (myPos.x > hero.pos.x) { return(Direction.North); } else if (myPos.x < hero.pos.x) { return(Direction.South); } else if (myPos.y > hero.pos.y) { return(Direction.West); } else { return(Direction.East); } } else if (Math.Abs(myPos.x - hero.pos.x) + Math.Abs(myPos.y - hero.pos.y) == 1) { //Maybe there's a tavern if (myPos.x < size && gameState.board[myPos.x + 1][myPos.y] == Tile.TAVERN) { return(Direction.South); } if (myPos.y < size && gameState.board[myPos.x][myPos.y + 1] == Tile.TAVERN) { return(Direction.East); } if (myPos.x > 0 && gameState.board[myPos.x - 1][myPos.y] == Tile.TAVERN) { return(Direction.North); } if (myPos.y > 0 && gameState.board[myPos.x][myPos.y - 1] == Tile.TAVERN) { return(Direction.West); } return(Direction.Stay); } } } return(""); }