public int Lookahead1() { var clonedField = state.Field.Clone(); clonedField.Simulate(); return(BestMove.EvaluatePosition(state, clonedField)); }
public void BestMove_CellDifferenceCount(int w, int h, string cells, int result) { var f = new Field(w, h, cells); var g = new Game(); Assert.Equal(result, BestMove.EvaluatePosition(g, f)); }
public void BestMove_DoesntCrash() { state.ParseField(3, 3, "0,0,.,0,.,.,.,.,1"); var strat = new BestMove(1, 4); var move = strat.Act(state, _ => {}); }
// Update is called once per frame void Update() { if (Input.GetKeyDown("c")) { Heuristic(AIPawns[0]); Heuristic(AIPawns[1]); Heuristic(AIPawns[2]); bm = CalcbestMove(); // Debug.Log(bm.Pawn.gameObject.name + ": Best Move is: " + bm.Direction + " With score " + bm.BestScore); } }
public Path GetTeleportPath(Point fromLocation, Point toLocation) { MakeDistanceTable(toLocation); var path = new List <Point>(); path.Add(fromLocation); int idxPath = 1; var bestMove = new BestMove { Move = fromLocation, Result = PathingResult.DestinationNotReachedYet }; var move = GetBestMove(bestMove.Move, toLocation, BlockRange); while (move.Result != PathingResult.Failed && idxPath < 100) { // Reached? if (move.Result == PathingResult.Reached) { AddToListAtIndex(path, toLocation, idxPath); idxPath++; return(new Path() { Found = true, Points = path.GetRange(0, idxPath) }); } // Perform a redundancy check int nRedundancy = GetRedundancy(path, idxPath, move.Move); if (nRedundancy == -1) { // no redundancy AddToListAtIndex(path, move.Move, idxPath); idxPath++; } else { // redundancy found, discard all redundant steps idxPath = nRedundancy + 1; AddToListAtIndex(path, move.Move, idxPath); } move = GetBestMove(move.Move, toLocation, BlockRange); } return(new Path() { Found = false, Points = null }); }
public BestMove CalcbestMove() { List <BestMove> bestMoves = new List <BestMove>(); BestMove bmPawn0 = new BestMove(AIPawns[0], Heuristic(AIPawns[0]), bestMove); BestMove bmPawn1 = new BestMove(AIPawns[1], Heuristic(AIPawns[1]), bestMove); BestMove bmPawn2 = new BestMove(AIPawns[2], Heuristic(AIPawns[2]), bestMove); bestMoves.Add(bmPawn0); bestMoves.Add(bmPawn1); bestMoves.Add(bmPawn2); List <BestMove> SortedList = bestMoves.OrderBy(o => o.BestScore).ToList(); SortedList.Reverse(); // Debug.Log(bestMoves[0].Direction +" " + bestMoves[1].Direction + " "+ bestMoves[2].Direction); return(SortedList[0]); }
public Action(int[] vAct) { move = BestMove.Move; point = new Point(); win = false; if (vAct != null && vAct.Length >= 1) move = (BestMove)vAct[0]; switch (move) { case BestMove.Heal: case BestMove.Buy: case BestMove.Move: case BestMove.AStar: case BestMove.Joker: case BestMove.GoPokeCenter: case BestMove.KillGary: case BestMove.CatchPokemon: point = new Point(vAct[1], vAct[2]); break; case BestMove.Battle: point = new Point(vAct[1], vAct[2]); win = vAct[3] == 1; break; } }
public void Turn(BestMove turnDir) { if (turnDir == BestMove.TurnRight) { switch (this.direcition) { case Direction.North: this.direcition = Direction.East; break; case Direction.South: this.direcition = Direction.West; break; case Direction.East: this.direcition = Direction.South; break; case Direction.West: this.direcition = Direction.North; break; } } else if(turnDir == BestMove.TurnLeft) { switch (this.direcition) { case Direction.North: this.direcition = Direction.West; break; case Direction.South: this.direcition = Direction.East; break; case Direction.East: this.direcition = Direction.North; break; case Direction.West: this.direcition = Direction.South; break; } } totalCost -= 1; listenerInfo(this); Map.Instance.GetTile(this.Pos).listUpdView(); }
public int Eval() { return(BestMove.EvaluatePosition(state, state.Field)); }
static BestMove AlphaBeta(Piece[,] board, int depth, int α, int β, bool maximizingPlayer, Move _move) { Counter++; if (depth == 0) { BoardData boardData = BoardValue(board); if (HashedBoard.ContainsKey(boardData.Hash)) { return new BestMove { Value = HashedBoard[boardData.Hash] } } ; if (!_move.IsKilling) { if (!HashedBoard.ContainsKey(boardData.Hash)) { HashedBoard.Add(boardData.Hash, boardData.Value); } return(new BestMove { Value = boardData.Value }); } else { BestMove bestMove = AlphaBetaForKillingMoves(board, 0, Int32.MinValue, Int32.MaxValue, true); if (!HashedBoard.ContainsKey(boardData.Hash)) { HashedBoard.Add(boardData.Hash, bestMove.Value); } return(bestMove); } } if (maximizingPlayer) { int value = Int32.MinValue; List <Move> moves = GetAllValidMoves(board, false); BestMove bestMove = new BestMove(); foreach (Move move in moves) { if (move.From.I == move.To.I && move.From.J == move.To.J) { continue; } Piece piece = board[move.To.I, move.To.J]; board[move.To.I, move.To.J] = board[move.From.I, move.From.J]; board[move.To.I, move.To.J].Position.I = move.To.I; board[move.To.I, move.To.J].Position.J = move.To.J; board[move.From.I, move.From.J] = null; value = Math.Max(value, AlphaBeta(board, depth - 1, α, β, false, move).Value); board[move.From.I, move.From.J] = board[move.To.I, move.To.J]; board[move.From.I, move.From.J].Position.I = move.From.I; board[move.From.I, move.From.J].Position.J = move.From.J; board[move.To.I, move.To.J] = piece; bestMove.Value = value; if (value > α) { bestMove.Move = move; } α = Math.Max(α, value); if (α >= β) { break; } } return(bestMove); } else { int value = Int32.MaxValue; List <Move> moves = GetAllValidMoves(board, true); foreach (Move move in moves) { if (move.From.I == move.To.I && move.From.J == move.To.J) { continue; } Piece piece = board[move.To.I, move.To.J]; board[move.To.I, move.To.J] = board[move.From.I, move.From.J]; board[move.To.I, move.To.J].Position.I = move.To.I; board[move.To.I, move.To.J].Position.J = move.To.J; board[move.From.I, move.From.J] = null; value = Math.Min(value, AlphaBeta(board, depth - 1, α, β, true, move).Value); board[move.From.I, move.From.J] = board[move.To.I, move.To.J]; board[move.From.I, move.From.J].Position.I = move.From.I; board[move.From.I, move.From.J].Position.J = move.From.J; board[move.To.I, move.To.J] = piece; β = Math.Min(β, value); if (α >= β) { break; } } return(new BestMove { Value = value }); } }
static BestMove AlphaBetaForKillingMoves(Piece[,] board, int depth, int α, int β, bool maximizingPlayer) { if (maximizingPlayer) { int value = Int32.MinValue; List <Move> moves = GetAllValidMoves(board, false); BestMove bestMove = new BestMove(); moves = moves.Where(x => x.IsKilling).ToList(); if (moves.Count == 0) { return new BestMove { Value = BoardValue(board).Value } } ; foreach (Move move in moves) { if (move.From.I == move.To.I && move.From.J == move.To.J) { continue; } Piece piece = board[move.To.I, move.To.J]; board[move.To.I, move.To.J] = board[move.From.I, move.From.J]; board[move.To.I, move.To.J].Position.I = move.To.I; board[move.To.I, move.To.J].Position.J = move.To.J; board[move.From.I, move.From.J] = null; value = Math.Max(value, AlphaBetaForKillingMoves(board, depth + 1, α, β, false).Value); board[move.From.I, move.From.J] = board[move.To.I, move.To.J]; board[move.From.I, move.From.J].Position.I = move.From.I; board[move.From.I, move.From.J].Position.J = move.From.J; board[move.To.I, move.To.J] = piece; bestMove.Value = value; if (value > α) { bestMove.Move = move; } α = Math.Max(α, value); if (α >= β) { break; } } return(bestMove); } else { int value = Int32.MaxValue; List <Move> moves = GetAllValidMoves(board, true); moves = moves.Where(x => x.IsKilling).ToList(); if (moves.Count == 0) { return new BestMove { Value = BoardValue(board).Value } } ; foreach (Move move in moves) { if (move.From.I == move.To.I && move.From.J == move.To.J) { continue; } Piece piece = board[move.To.I, move.To.J]; board[move.To.I, move.To.J] = board[move.From.I, move.From.J]; board[move.To.I, move.To.J].Position.I = move.To.I; board[move.To.I, move.To.J].Position.J = move.To.J; board[move.From.I, move.From.J] = null; value = Math.Min(value, AlphaBetaForKillingMoves(board, depth + 1, α, β, true).Value); board[move.From.I, move.From.J] = board[move.To.I, move.To.J]; board[move.From.I, move.From.J].Position.I = move.From.I; board[move.From.I, move.From.J].Position.J = move.From.J; board[move.To.I, move.To.J] = piece; β = Math.Min(β, value); if (α >= β) { break; } } return(new BestMove { Value = value }); } }
public void TurnAsh(BestMove dir) { Ash.Turn(dir); }