Beispiel #1
0
        public List <MoveScenarios> getAllowMoveScenarios(Board board, int color)
        {
            List <MoveScenarios> allMoveScenarios    = new List <MoveScenarios>();
            List <MoveScenarios> allCaptureScenarios = new List <MoveScenarios>();

            List <Position> piecePositions = board.getPiecePositions(color);

            foreach (Position currPosition in piecePositions)
            {
                MoveScenarios captureScenarios = getAllCaptureScenarios(board, currPosition);

                if (captureScenarios != null)
                {
                    allCaptureScenarios.Add(captureScenarios);
                }
                else
                {
                    MoveScenarios moveScenarios = getAllMoveScenarios(board, currPosition);

                    if (moveScenarios.Count() > 0)
                    {
                        allMoveScenarios.Add(moveScenarios);
                    }
                }
            }

            if (allCaptureScenarios.Count > 0)
            {
                return(allCaptureScenarios);
            }

            return(allMoveScenarios);
        }
Beispiel #2
0
        public void execRandomMove()
        {
            List <MoveScenarios> moves        = getAllowPlayerMoves();
            MoveScenarios        moveScenario = moves[new Random().Next(0, moves.Count)];

            execMove(moveScenario);
        }
Beispiel #3
0
        /*
         * Return true if move is end
         */
        public bool execPlayerMove(Board board, Position movePos)
        {
            if (currMoveScenarios == null)
            {
                allMoveScenarios  = moveFinder.getMoveScenarios(board, movePos);
                currMoveScenarios = allMoveScenarios;
                currMoveIndex     = 0;
            }
            else
            {
                currMoveScenarios = currMoveScenarios.getMatchScenarios(movePos, currMoveIndex);
                currMoveIndex++;

                if (currMoveScenarios.Count() == 1 && currMoveScenarios.getScenario(0).Count == currMoveIndex)
                {
                    execScenario(board, currMoveScenarios, 0);

                    currMoveScenarios = null;

                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        public MoveController()
        {
            allMoveScenarios  = null;
            currMoveScenarios = null;
            currMoveIndex     = 0;

            moveFinder = new MoveFinder();
        }
Beispiel #5
0
        public MoveScenarios getMoveScenarios(Board board, Position basePosition)
        {
            MoveScenarios captureScenarios = getAllCaptureScenarios(board, basePosition);

            if (captureScenarios != null)
            {
                return(captureScenarios);
            }

            return(getAllMoveScenarios(board, basePosition));
        }
Beispiel #6
0
 public void execMove(MoveScenarios bestScenario)
 {
     if (bestScenario != null)
     {
         MoveController.execScenario(board, bestScenario, 0);
     }
     else
     {
         areAllowMoves = false;
     }
 }
Beispiel #7
0
        public void deletePlayerMove(Position toMovePos)
        {
            if (currMoveScenarios == null)
            {
                return;
            }

            if (toMovePos.Equals(currMoveScenarios.getFromPosition()))
            {
                currMoveScenarios = null;
                currMoveIndex     = 0;
            }
            else
            {
                int i = 0;

                foreach (Position p in currMoveScenarios.getScenario(0))
                {
                    if (!p.Equals(toMovePos))
                    {
                        break;
                    }

                    i++;
                }

                currMoveIndex = currMoveIndex - i - 1;

                if (currMoveIndex == -1)
                {
                    currMoveScenarios = allMoveScenarios;
                    currMoveIndex     = 0;
                }
                else
                {
                    Position currPos = currMoveScenarios.getScenario(0)[currMoveIndex];
                    currMoveScenarios = allMoveScenarios.getMatchScenarios(currPos, currMoveIndex);
                }
            }
        }
Beispiel #8
0
        public static void execScenario(Board board, MoveScenarios scenarios, int scenarioIndex)
        {
            List <Position> moves = new List <Position>();

            moves.Add(scenarios.getFromPosition());
            moves.AddRange(scenarios.getScenario(scenarioIndex));

            Position lastPosition = moves[moves.Count - 1];

            board.move(scenarios.getFromPosition(), lastPosition);

            if (board.isTurnToDame(lastPosition))
            {
                board.turnToDame(lastPosition);
            }

            Direction direction;
            Position  currPos;

            for (int i = 0; i < moves.Count - 1; i++)
            {
                direction = Direction.getDirection(moves[i], moves[i + 1]);
                currPos   = new Position(moves[i]);

                currPos.move(direction);

                while (!currPos.Equals(moves[i + 1]))
                {
                    if (!Board.isEmpty(board.getPiece(currPos)))
                    {
                        board.removePiece(currPos);
                    }

                    currPos.move(direction);
                }
            }

            board.switchCurrentColor();
        }