Esempio n. 1
0
        static void Main(string[] args)
        {
            if (args[0] != null)
            {
                // input of number of games to play
                maxGames = Int32.Parse(args[0]);
            }

            // Read any previous boards
            List <BoardImage> PriorBoards = GetSavedBoarImages();

            // Create list of legal moves
            List <LegalMove> LegalMoves = GetLegalMoves();

            bool done  = false;
            int  count = 0;

            while (!done)
            {
                // Create new board
                PegBoard board = new PegBoard();
                board.LegalMoves  = LegalMoves;
                board.PriorBoards = PriorBoards;

                // Play Game
                //logger.Info("**New Game**");
                PegBoard.Outcome outcome = board.PlayGame();

                // add the board to the array of images
                PriorBoards.Add(BuildBoardImage(board, PriorBoards.Count + 1, outcome));

                // if game lost or number of moves greater than ten, save board
                if (outcome == PegBoard.Outcome.Champ)
                {
                    done = true;
                }

                // display the board moves
                //logger.Info("Board moves:");
                //foreach (var move in board.Moves)
                //{
                //    logger.Info(move.ToString());
                //}
                logger.Info($"Game: {count + 1} Outcome : {outcome.ToString()} Pegs Remaining: {board.PegsRemaining()}");

                count++;
                if (count == maxGames)
                {
                    done = true;
                }
            }
            // save the collection of boards
            SaveBoardImages(PriorBoards);
        }
Esempio n. 2
0
        private static BoardImage BuildBoardImage(PegBoard board, int arrSize, PegBoard.Outcome outcome)
        {
            BoardImage boardImage = new BoardImage();

            boardImage.BoardId  = arrSize.ToString("0000#");
            boardImage.Outcome  = outcome.ToString();
            boardImage.PegHoles = board.PegHoles;

            // list of moves
            List <string> moveList = new List <string>();

            foreach (var move in board.Moves)
            {
                moveList.Add(move.ToString());
            }
            boardImage.Moves = moveList;
            return(boardImage);
        }