Exemplo n.º 1
0
 List <PotentialMove> Append(List <PotentialMove> moves, PotentialMove move)
 {
     return(moves.Concat(new List <PotentialMove>()
     {
         move
     }).ToList());
 }
Exemplo n.º 2
0
        public void FallActionsFallPiece2x2()
        {
            var board = builder.FromTypeGrid(new int[, ] {
                { 0, 1, 2, 0 },
                { 1, 0, 0, 2 },
                { 1, 1, 1, 2 },
                { 0, 1, 1, 2 }
            });
            var game = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

            var moves = new PotentialMove[] {
                new PotentialMove(c10, Orientation.Top),
                new PotentialMove(c01, Orientation.Right),
                new PotentialMove(c21, Orientation.Left),
            };

            foreach (var move in moves)
            {
                var simulator = MoveSimulator.FromPotentialMove(board, move, game.NextPieceIfPlaying(move));
                simulator.Simulate();
                Assert.IsTrue(simulator.IsMovePossible());
                var actions     = simulator.GetMove().consequences;
                var fallActions = actions.Where(IsFallAction);
                foreach (var action in fallActions)
                {
                    Assert.AreEqual(2, (action as FallAction).rows);
                }
            }
        }
Exemplo n.º 3
0
    void NewMove(int x, int y, GameObject piece, Board previousGameBoard)
    {
        Tile          potentialMoveTile = tiles[x, y];
        PotentialMove newMove           = new PotentialMove();

        newMove.tile  = potentialMoveTile;
        newMove.piece = piece;

        AIBoard potentialNewBoard = new AIBoard();

        Board potentialBoard = new Board();

        foreach (GameObject whiteAdd in previousGameBoard.white)
        {
            potentialBoard.white.Add(whiteAdd);
        }
        foreach (GameObject blackAdd in previousGameBoard.black)
        {
            potentialBoard.black.Add(blackAdd);
        }
        if (newMove.tile.piece != null)
        {
            if (newMove.tile.piece.GetComponent <UnitInfo>().colour == 0)
            {
                potentialBoard.white.Remove(newMove.tile.piece);
            }
            else
            {
                potentialBoard.black.Remove(newMove.tile.piece);
            }
        }
        potentialBoard.GetBoardValue(currentTurn);
        newMove.ResultingBoard = potentialBoard;
        potentialMoves.Add(newMove);
    }
 ///////////////////////////////////////////////////////////////////////////
 public override PotentialMove GetMove()
 {
     if (targetChessPiece != null) {
                 PotentialMove move = new PotentialMove (GetComponent<ChessPiece> (), targetChessPiece.GetX (), targetChessPiece.GetY (), targetChessPiece);
                 move.SetBossAbility (true);
                 return move;
         } else {
                 Debug.Log ("ERROR! " + gameObject.name + " tried to get a potential move on a null target!");
                 return null;
         }
 }
Exemplo n.º 5
0
        public void CanSimulateRotatedMove()
        {
            var board = builder.FromTypeGrid(new int[, ] {
                { 0, 1, 2, 0 },
                { 1, 0, 0, 2 },
                { 1, 1, 1, 2 },
                { 0, 1, 1, 2 }
            });
            var game = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3));

            var move      = new PotentialMove(c03, Orientation.Right);
            var simulator = MoveSimulator.FromPotentialMove(board, move, game.NextPieceIfPlaying(move));

            simulator.Simulate();
            Assert.IsTrue(simulator.IsMovePossible());
        }
Exemplo n.º 6
0
    public void MakeMove(BoardState board)
    {
        Debug.Log("AI IS MAKING A MOVE");

        // first, let's get a list of all of our active units
        List <Unit> activeUnits = new List <Unit>();

        foreach (Grid grid in board.GetGrids())
        {
            if (grid.GetActiveUnit(team) != null)
            {
                activeUnits.Add(grid.GetActiveUnit());
            }
        }

        // what are our potential moves with them?
        List <PotentialMove> potentialMoves = new List <PotentialMove>();

        foreach (Unit unit in activeUnits)
        {
            foreach (Vector2 direction in directions)
            {
                int distance = unit.GetGrid().GetOccupants().Length;

                for (int i = 1; i <= distance; i++)
                {
                    Vector2 coords = unit.GetGrid().GetCoords() + (i * direction);

                    bool outOfX = coords.x < 0 || coords.x >= board.GetGrids().GetLength(0);
                    bool outOfY = coords.y < 0 || coords.y >= board.GetGrids().GetLength(1);
                    if (outOfX || outOfY)
                    {
                        break;
                    }

                    Grid          targetGrid = board.GetGrids()[(int)coords.x, (int)coords.y];
                    PotentialMove move       = new PotentialMove(unit, targetGrid);
                    potentialMoves.Add(move);
                    ValidGrids grids = controller.GetValidGrids(unit, targetGrid);

                    if (grids.valid)
                    {
                        potentialMoves.Add(new PotentialMove(unit, targetGrid));
                    }
                }
            }
        }

        // if any of those are an enemy, take it
        List <PotentialMove> enemies = new List <PotentialMove>();

        foreach (PotentialMove move in potentialMoves)
        {
            if (move.targetGrid.GetActiveUnit() != null &&
                !move.targetGrid.GetActiveUnit().GetTeam().Equals(team))
            {
                enemies.Add(move);
            }
        }
        if (enemies.Count > 0)
        {
            controller.RandomDelay(this, minWait, maxWait, enemies);
        }

        // okay, no enemies in range, move toward one then
        else
        {
            controller.RandomDelay(this, minWait, maxWait, potentialMoves);
        }
    }