Beispiel #1
0
        public Game CreateNewGame()
        {
            var game = new Game();

            game.Players = new List<Player> { new Player(GameSide.White), new Player(GameSide.Black, true) };
            game.Board = _boardBuilder.CreateNewBoard();
            return game;
        }
Beispiel #2
0
        public void StartGame()
        {
            Game = _gameBuilder.CreateNewGame();
            _boardHandler.Draw(Game.Board);

            while (true)
            {
                var move = _moveHandler.GetNextMove(Game);
                _moveHandler.HandleMove(Game, move);
                _boardHandler.Draw(Game.Board);
            }
        }
Beispiel #3
0
        public Move SelectBestMove(Game game, List<Move> availableMoves)
        {
            var bestValue = -9999;
            Move bestMove = null;

            foreach (var move in availableMoves)
            {
                var moveScore = _moveEvaluator.EvaluateMove(game, move);
                if (bestMove == null || (moveScore > bestValue))
                {
                    bestMove = move;
                    bestValue = moveScore;
                }
            }

            return bestMove;
        }
Beispiel #4
0
        private List<Move> GetAllAvailableMove(Game game, GameSide gameSide)
        {
            var availableMoves = new List<Move>();

            foreach (var figure in game.Board.Figures.Where(x => x.Side == gameSide))
            {
                var allMovesForFigure = figure.GetFieldsICanMoveTo();
                foreach (var locationToMoveTo in allMovesForFigure)
                {
                    var move = new Move(figure.Location, locationToMoveTo, gameSide);
                     if (_moveValidator.MoveIsValid(move,game.Board))
                         availableMoves.Add(move);
                }
            }

            return availableMoves;
        }
Beispiel #5
0
        public MoveResult HandleMove(Game game, Move move)
        {
            var existingFigure = game.Board.GetFigureOnLocation(move.To);
            if (existingFigure != null)
                game.Board.CaptureFigure(existingFigure);

            var figureToMove = game.Board.GetFigureOnLocation(move.From);
            if (figureToMove.ShouldConvert(move))
            {
                game.Board.ConvertFigure(figureToMove, move);
            }
            else
            {
                figureToMove.Move(move);
            }

            return GetMoveResult(game.Board, move.Side);
        }
Beispiel #6
0
        public Move GetNextMove(Game game)
        {
            var player = game.GetNextToMove();
            Move move;

            if (player.IsAIPlayer)
            {
                move = _moveGenerator.GenerateMove(game, player.GameSide);
            }
            else
            {
                while (true)
                {
                    move = _userMoveReader.FetchMove(player.GameSide);
                    if (_moveValidator.MoveIsValid(move, game.Board))
                        break;
                }
            }

            game.SwitchNextPlayer();
            return move;
        }
Beispiel #7
0
 public Move GenerateMove(Game game, GameSide gameSide)
 {
     var availableMoves = GetAllAvailableMove(game, gameSide);
     return _moveSelector.SelectBestMove(game, availableMoves);
 }
Beispiel #8
0
 public int EvaluateMove(Game game, Move move)
 {
     throw new System.NotImplementedException();
 }