Beispiel #1
0
        public bool addChildBoardStates(MoveFinder moveFinder)
        {
            List <MoveScenarios> allScenarios = moveFinder.getAllowMoveScenarios(BoardState, BoardState.CurrentColor);

            foreach (MoveScenarios currScenario in allScenarios)
            {
                for (int i = 0; i < currScenario.Count(); i++)
                {
                    Board newBoardState = new Board(BoardState);
                    MoveController.execScenario(newBoardState, currScenario, i);

                    ChildsContext.Push(
                        new MoveContext(
                            newBoardState,
                            currScenario.getFromPosition(),
                            currScenario.getScenario(i),
                            CurrDepth + 1,
                            this,
                            !IsMax
                            )
                        );
                }
            }

            IsVisited = true;

            if (allScenarios.Count > 0)
            {
                return(allScenarios[0].isCapture());
            }

            return(false);
        }
Beispiel #2
0
 public void execMove(MoveScenarios bestScenario)
 {
     if (bestScenario != null)
     {
         MoveController.execScenario(board, bestScenario, 0);
     }
     else
     {
         areAllowMoves = false;
     }
 }
Beispiel #3
0
        public Game(GameSettings gameSettings)
        {
            this.maxDepth = gameSettings.Depth;
            areAllowMoves = true;

            board    = new Board(gameSettings.International, gameSettings.PieceColor);
            moveCtrl = new MoveController();
            miniMax  = new MiniMax(maxDepth);

            this.moveTimeInSec = gameSettings.MoveTimeInSec;

            countdownTimer = new CountdownTimer();
        }
Beispiel #4
0
        private MoveScenarios getAllCaptureScenarios(Board board, Position basePosition)
        {
            int piece = board.getPiece(basePosition);
            Stack <MoveOptionsContext> stack        = new Stack <MoveOptionsContext>();
            List <List <Position> >    allScenarios = new List <List <Position> >();
            List <Position>            currScenario = new List <Position>();
            MoveOptionsContext         currContext;
            MoveOptions currMoveOpt;

            MoveOptions rootMoveOpt = new MoveOptions(new Board(board), basePosition);

            stack.Push(new MoveOptionsContext(rootMoveOpt));

            while (stack.Count > 0)
            {
                currContext = stack.Pop();
                currMoveOpt = currContext.CurrMoveOpt;

                if (!currContext.IsVisited)
                {
                    if (!currMoveOpt.Equals(rootMoveOpt))
                    {
                        currScenario.Add(currMoveOpt.CurrentPos);
                    }

                    currContext.IsVisited = true;
                    stack.Push(currContext);

                    List <Position> foundCapture = findCaptures(currMoveOpt.CurrentBoard, currMoveOpt.CurrentPos, piece);

                    foreach (Position currCapturePos in foundCapture)
                    {
                        Board newBoardState = new Board(currMoveOpt.CurrentBoard);
                        MoveController.execMove(newBoardState, currMoveOpt.CurrentPos, currCapturePos);

                        MoveOptions captureMoveOpt = new MoveOptions(newBoardState, currCapturePos);
                        currMoveOpt.Add(captureMoveOpt);

                        stack.Push(new MoveOptionsContext(captureMoveOpt));
                    }
                }
                else
                {
                    if (currMoveOpt.AllMoveOptPos.Count == 0 && currScenario.Count > 0)
                    {
                        List <Position> leafPath = new List <Position>();
                        leafPath.AddRange(currScenario);

                        allScenarios.Add(leafPath);
                    }

                    if (currScenario.Count > 0)
                    {
                        currScenario.RemoveAt(currScenario.Count - 1);
                    }
                }
            }

            if (allScenarios.Count == 0)
            {
                return(null);
            }

            return(new MoveScenarios(basePosition, allScenarios, true));
        }
Beispiel #5
0
 public MiniMax(int maxDepth)
 {
     this.maxDepth  = maxDepth;
     moveController = new MoveController();
     moveFinder     = new MoveFinder();
 }