Exemplo n.º 1
0
        public MatchEngine(IPlayer player1, IPlayer player2, int winScore)
        {
            _player1 = player1;
            _player2 = player2;

            _winScore = winScore;

            _startingPlayer = player1;
            _secondPlayer = player2;

            _engine = new GameEngine(_startingPlayer, _secondPlayer, new GameState());
            _matchInfo = new MatchInfo();

            _regroupBot = new Bot(REGROUP_SEARCH_DEPTH, Heuristics.MoveFarEval);
        }
Exemplo n.º 2
0
        public GamePlayViewModel(GameEngine engine)
        {
            _engine = engine;
            UpdateDisplayState();
            _selectedPiece = null;
            SelectTileCommand = new RelayCommand(param =>
            {
                if (engine.ActivePlayer is Human && _selectedPiece == null)
                {
                    Point chosenPoint = ParamToPoint(param);
                    if ((engine.CurrentState.PieceToMove == null && chosenPoint.Y == 7)
                        || (engine.CurrentState.PieceToMove != null && chosenPoint.Equals(engine.CurrentState.PieceToMove.Position)))
                    {
                        _selectedPiece = _engine.CurrentState.BoardPositions[chosenPoint.Y][chosenPoint.X];
                    }
                }
                else if (engine.ActivePlayer is Human)
                {
                    Point chosenPoint = ParamToPoint(param);
                    IMove chosenMove = null;
                    foreach (IMove move in engine.CurrentState.PossibleMoves)
                    {
                        if(move.Piece == _selectedPiece && move.End.Equals(chosenPoint))
                        {
                            chosenMove = move;
                            break;
                        }
                    }

                    if(chosenMove != null)
                    {
                        (engine.ActivePlayer as Human).ChosenMove = chosenMove;
                        (engine.ActivePlayer as Human).GotMove = true;
                        _selectedPiece = null;
                    }
                }
            }, param => { return true; });
        }
Exemplo n.º 3
0
        public MatchInfo Run()
        {
            while (_player1.Score < _winScore && _player2.Score < _winScore)
            {
                RoundInfo roundInfo =_engine.Run();
                if (_startingPlayer == _player1)
                {
                    roundInfo.Challenger = "Player 1";
                    roundInfo.Defender = "Player 2";
                }
                else
                {
                    roundInfo.Challenger = "Player 2";
                    roundInfo.Defender = "Player 1";
                }

                _matchInfo.PlayedRounds.AddLast(roundInfo);
                if (roundInfo.PlayerTwoWon)
                {
                    _secondPlayer.Score += roundInfo.Score;
                }
                else
                {
                    _startingPlayer.Score += roundInfo.Score;
                    IPlayer tmp = _startingPlayer;
                    _startingPlayer = _secondPlayer;
                    _secondPlayer = tmp;
                }

                GameState leftState = GameState.GenerateNextRound(_engine.CurrentState, true);
                GameState rightState = GameState.GenerateNextRound(_engine.CurrentState, false);

                bool doLeft = true;
                double leftValue = _regroupBot.GetMove(leftState).Value;
                double rightValue = _regroupBot.GetMove(rightState).Value;
                Debug.WriteLine("Left value: " + leftValue + ", right value: " + rightValue);
                if (leftValue > rightValue)
                {
                    doLeft = false;
                }

                roundInfo.LeftValue = leftValue;
                roundInfo.RightValue = rightValue;
                roundInfo.DoLeft = doLeft;

                _engine = new GameEngine(_startingPlayer, _secondPlayer, GameState.GenerateNextRound(_engine.CurrentState, doLeft));
            }

            _matchInfo.Player1Score = _player1.Score;
            _matchInfo.Player2Score = _player2.Score;
            _matchInfo.Player2Won = _player2.Score > _player1.Score;

            return _matchInfo;
        }