示例#1
0
文件: Game.cs 项目: pgillett/PacMan
        public Game(IGameClock gameClock, IGameSettings settings)
        {
            _gameClock        = gameClock;
            _settings         = settings;
            _gameStateMachine = new GameStateMachine(settings, _gameNotifications, this);
            var gameState = new GameState(settings);

            _gameState = gameState;
            _gameStateMachineInstance = _gameStateMachine.CreateInstanceLift(gameState);
            Walls          = _settings.Walls.Union(_settings.Doors).ToList().AsReadOnly();
            _fruitForLevel = new[] { new Fruit(_settings.Fruit, FruitType.Cherry) };
        }
示例#2
0
        internal Ghost Move(Game game, IReadOnlyGameState gameState)
        {
            if (Edible && gameState.TickCounter % 2 == 1)
            {
                return(this);
            }

            if (GhostWalkingOutOfGhostHouse(game))
            {
                if (game.StartingCoins.Count - game.Coins.Count >= NumberOfCoinsRequiredToExitHouse)
                {
                    var outDirection = Direction.Up;
                    var target       = game.Doors.First().Above;
                    if (target.X < Location.X)
                    {
                        outDirection = Direction.Left;
                    }
                    else if (target.X > Location.X)
                    {
                        outDirection = Direction.Right;
                    }
                    var newGhostLocation = Location + outDirection;

                    return(WithNewLocationAndDirection(newGhostLocation, outDirection));
                }
                else
                {
                    return(this);
                }
            }

            var nextDirection = CurrentStrategy.GetNextDirection(this, game);

            if (nextDirection is Direction newDirection)
            {
                var newGhostLocation = Location + newDirection;
                if (game.Portals.TryGetValue(newGhostLocation, out var otherEndOfThePortal))
                {
                    newGhostLocation = otherEndOfThePortal + newDirection;
                }
                if (game.GhostHouse.Contains(newGhostLocation))
                {
                    return(WithNewLocationAndDirection(newGhostLocation, newDirection)
                           .WithNewStatusAndStrategy(GhostStatus.Alive, ChaseStrategy));
                }
                return(WithNewLocationAndDirection(newGhostLocation, newDirection));
            }
            else
            {
                return(this);
            }
        }
示例#3
0
        public Game(IGameClock gameClock, IGameSettings settings)
        {
            _gameClock = gameClock;
            _settings  = settings;
            var actions = new Actions(settings, _gameNotifications);

            _gameStateMachine = new GameStateMachine(actions, settings, this);
            var gameState = new GameState(settings);

            _gameState = gameState;
            _gameStateMachineInstance = _gameStateMachine.CreateInstanceLift(gameState);
            WallsAndDoors             = _settings.Walls.Union(_settings.Doors).ToList().AsReadOnly();
            Walls            = _settings.Walls;
            _fruitForLevel   = new[] { new Fruit(_settings.Fruit, FruitType.Cherry) };
            GhostHouseMiddle = CalculateMiddleOfGhostHouse(settings.GhostHouse);
        }
示例#4
0
        public GameMove GetNextMove(IReadOnlyGameState state)
        {
            Malom3.GameState otherState = new Malom3.GameState();

            // Alle Informationen in den anderen Zustand übertragen
            otherState.block         = false;
            otherState.KLE           = false;
            otherState.phase         = state.GetPhase(state.NextToMove) == Phase.Placing ? 1 : 2;
            otherState.over          = false;
            otherState.LastKLE       = 0;
            otherState.SideToMove    = playerConversion[state.NextToMove];
            otherState.T             = Enumerable.Range(0, GameState.FIELD_SIZE).Select(x => occupationConversion[state.Board[reverseCoordinateConversion[x]]]).ToArray();
            otherState.SetStoneCount = new[] { state.GetStonesPlaced(Player.White), state.GetStonesPlaced(Player.Black) };
            otherState.StoneCount    = new[] { state.GetCurrentStones(Player.White), state.GetCurrentStones(Player.Black) };
            // otherState.MoveCount wird von keiner für uns interessanten KI verwendet
            // otherState.block und otherState.winner geben lediglich Informationen nach Spielende a

            Malom3.Move move = player.ToMove(otherState);
            GameMove    convertedMove;

            // In Malom gibt die KI immer zunächst einen Zug zurück, der keine Information zum Schlagen enthält.
            // Wenn wir diese benötigen, müssen wir einen weiteren Zug anfordern.

            if (move is Malom3.MoveKorong)
            {
                var mo = move as Malom3.MoveKorong;
                convertedMove = mo == null ? null :GameMove.Move(reverseCoordinateConversion[mo.hon], reverseCoordinateConversion[mo.hov]);
            }
            else
            {
                var mo = move as Malom3.SetKorong;
                convertedMove = mo == null ? null : GameMove.Place(reverseCoordinateConversion[mo.hov]);
            }

            if (state.IsValidMove(convertedMove) == MoveValidity.ClosesMill)
            {
                // Keine Ahnung für was KLE steht, aber es bedeutet, dass der Spieler einen Zug zurückgeben soll, der einen Stein entfernt
                // Oder, in Malom-Terminologie, einen LeveszKorong
                otherState.KLE = true;
                Malom3.LeveszKorong mo = player.ToMove(otherState) as Malom3.LeveszKorong;
                convertedMove = mo == null ? null : convertedMove.WithRemove(reverseCoordinateConversion[mo.hon]);
            }

            return(convertedMove);
        }