protected override IMove GetNextMove_Impl(IGameBoard board)
        {
            m_GameBoard = board as GameBoard;
            InkCollectorStrokeEventHandler handler = new InkCollectorStrokeEventHandler(m_InkPicture_Stroke);
            IMove move = null;

            m_Waiter = new EventWaitHandle(false, EventResetMode.ManualReset);
            m_InkPicture.Stroke += handler;

            try
            {
                while (move == null)
                {
                    m_Waiter.Reset();
                    if (m_Waiter.WaitOne())
                    {
                        move = m_Move;
                    }
                }
            }
            finally
            {
                m_InkPicture.Stroke -= handler;
            }

            return move;
        }
 public static void Display(IGameBoard board)
 {
     for (int y = board.BoardHeight - 1; y >= 0 ; --y)
     {
         Console.WriteLine(new String('-', board.BoardWidth * (CASE_PADDING + 2)));
         for (int x = 0; x < board.BoardWidth; x += 1)
         {
             string caseValue;
             IToken currentToken = board.GetToken(x, y);
             if (currentToken != null)
             {
                 caseValue = currentToken.GetDisplayValue().ToString();
             }
             else
             {
                 caseValue = string.Format("({0},{1})", x, y);
             }
             Console.Write("|");
             Console.Write(caseValue.PadBoth(CASE_PADDING));
             Console.Write("|");
         }
         Console.WriteLine();
     }
     Console.WriteLine(new String('-', board.BoardWidth * (CASE_PADDING + 2)));
 }
        public Direction GetNextMove(IGameBoard board, bool lastMoveResult)
        {
            if (lastMoveResult)
                return currentDirection;

            switch (currentDirection)
            {
                case Direction.Up:
                    currentDirection = Direction.Left;
                    break;

                case Direction.Left:
                    currentDirection = Direction.Down;
                    break;

                case Direction.Down:
                    currentDirection =  Direction.Right;
                    break;

                case Direction.Right:
                    currentDirection =  Direction.Up;
                    break;

                default:
                    throw new Exception("TILT - Cannot get here, what happened?");
            }

            return currentDirection;
        }
Example #4
0
 internal Game(IDeck deck, IGameBoard board)
 {
     _deck = deck;
     _board = board;
     _events = new Queue<GameEvent>();
     _users = new List<Guid>();
     _hands = new Dictionary<Guid, List<Card>>();
 }
Example #5
0
        public GameBoardVM(IGameBoard gameboard, IEnumerable<ICellVM> cells)
        {
            _gameBoard = gameboard;
            Cells = new List<ICellVM>(cells);

            foreach (var cellVM in Cells)
            {
                cellVM.NumberChanged += CellVMNumberChanged;
            }
        }
Example #6
0
        public TicTacToeGame(IGameBoard gameBoard, IDisplayHelper displayHelper, IRandomNumberGenerator randomNumberGenerator)
        {
            _gameBoard = gameBoard;
            _displayHelper = displayHelper;
            _randomNumberGenerator = randomNumberGenerator;

            // Started with player factory but I think it was over engineered so replaced it with direct player creations
            PlayerO = new Player('O');
            PlayerX = new Player('X');
        }
        public IGameBoard SolveToEnd(IGameBoard board)
        {
            bool lastMove = true;

            while (!board.GameOver)
            {
                lastMove = board.Move(strat.GetNextMove(board, lastMove));
            }

            return board;
        }
Example #8
0
 public GameLinePoint[] CheckWinnerLine(IGameBoard gameBoard)
 {
     foreach (var line in gameBoard.SelectAllLines())
     {
         GameLinePoint[] testLine = line.ToArray();
         bool winner = CheckWinnerLine(testLine);
         if(winner)
             return testLine;
     }
     return null;
 }
        protected override bool MakeMove(IPlayer player, IGameBoard board, IGameMove move)
        {
            if (!this.IsMoveValid(board, move.LaneIndex, move.Die.Value, player.Name))
                return false;

            var targetLane = board.Lanes[move.LaneIndex + move.Die.Value];
            if (targetLane.Count == 1 && targetLane[0].Player != player.Name)
            {
                targetLane.MovePiece(board.Bar);
            }
            move.Lane.MovePiece(targetLane);
            return true;
        }
        public Direction GetNextMove(IGameBoard board, bool lastMoveResult)
        {
            Direction bestDir = fallBackStrat.GetNextMove(board, lastMoveResult);
            int bestScore = 0;

            foreach (Direction direction in Enum.GetValues(typeof(Direction)))
            {
                var candidateScore = ScoreAllPossibleBoards(board, direction, searchDepth);
                if (bestScore < candidateScore)
                {
                    bestDir = direction;
                    bestScore = candidateScore;
                }
            }

            return bestDir;
        }
Example #11
0
        public virtual void Initialize()
        {
            GameTime = new GameTime();

            GameBoard = new GameBoard(800, 800);
            ComponentService = new ComponentService();
            AiStore = new ConcurrentMemoryStore<string, IArtificialIntelligence>();
            MoveUnitService = new MoveUnitService(ComponentService,AiStore);

            Agent = new Agent(new EventValidationService(GameBoard, ComponentService), ComponentService, MoveUnitService, AiStore, GameTime);

            Agent.Register<ArtificialIntelligenceSpa>();
            Agent.Register<ArtificialIntelligenceNku>();
            Agent.Register<ArtificialIntelligenceNhu>();
            Agent.Register<ArtificialIntelligenceJfi>();

            GameMaster = new GameMaster(Agent, GameBoard);
        }
        protected override IMove GetNextMove_Impl(IGameBoard board)
        {
            GameBoard b = (GameBoard) board;

            if (b.MovesRemaining > 0)
            {
                Move m = null;

                List<Move> twoPointMoves = new List<Move>();
                List<Move> onePointMoves = new List<Move>();

                foreach (Move am in b.AvailableMoves)
                {
                    int score = b.SpeculateMove(am, this).Count;
                    if (score == 2)
                    {
                        twoPointMoves.Add(am);
                    }
                    else if (score == 1)
                    {
                        onePointMoves.Add(am);
                    }
                }

                if (twoPointMoves.Count > 0)
                {
                    m = twoPointMoves[m_RNG.Next(0, twoPointMoves.Count - 1)];
                }
                else if (onePointMoves.Count > 0)
                {
                    m = onePointMoves[m_RNG.Next(0, onePointMoves.Count - 1)];
                }
                else
                {
                    m = b.AvailableMoves[m_RNG.Next(0, b.AvailableMoves.Count - 1)];
                }

                m.SetPlayer(this);

                return m;
            }

            throw new InvalidOperationException("Attempt to move when board is filled");
        }
        protected override bool MakeMove(IPlayer player, IGameBoard board, IGameMove move)
        {
            if (move.Lane != board.Bar || !this.IsMoveValid(board, move.Die.Value, player.Name))
                return false;

            var lane = move.Lane;
            var pieceIndex = lane.Count - 1;
            while (lane[pieceIndex].Player != player.Name)
                pieceIndex--;
            var piece = lane[pieceIndex];
            lane.RemoveAt(pieceIndex);
            var targetLane = board.Lanes[move.Die.Value - 1];
            if (targetLane.Count == 1 && targetLane[0].Player != player.Name)
            {
                targetLane.MovePiece(lane);
            }
            targetLane.Add(piece);
            return true;
        }
Example #14
0
        public DefaultGame(IApp app, IGameBoard board, IPlayer player1, IPlayer player2, IGameRules gameRules)
        {
            if (app == null)
                throw new ArgumentNullException(nameof(app));
            if (player1 == null)
                throw new ArgumentNullException(nameof(player1));
            if (player2 == null)
                throw new ArgumentNullException(nameof(player2));
            if (player1.Equals(player2))
                throw new ArgumentException($"{nameof(player1)} is the same as {nameof(player2)}");
            if (player1.Name == player2.Name)
                throw new ArgumentException(
                    $"{nameof(player1)}.{nameof(player1.Name)} == {nameof(player2)}.{nameof(player2.Name)}");

            this.App = app;
            this.Players = new [] { player1, player2 };

            var reversedBoard = new DefaultBoard(new ReversedLanes(board.Lanes), board.Bar, board.BearedOff);
            this.Boards = new [] { board, reversedBoard };

            this.Rules = gameRules;
        }
        private int ScoreAllPossibleBoards(IGameBoard board, Direction direction, int depthToSearch)
        {
            int cumulativeScore = 0;
            int boardsTested = 0;

            var possibleBoardsAfterMove = board.GetAllPossibleResults(direction);

            foreach (IGameBoard gb in possibleBoardsAfterMove)
            {
                cumulativeScore += ScoreSingleBoard(gb);
                boardsTested++;
            }

            if (boardsTested == 0)
            {
                return 0;
            }

            if (depthToSearch <= 1)
            {
                return (cumulativeScore / boardsTested);
            }

            int depthTotal = 0;
            int boardsExplored = 0;
            foreach (IGameBoard gb in possibleBoardsAfterMove)
            {
                foreach (Direction d in Enum.GetValues(typeof(Direction)))
                {
                    depthTotal += ScoreAllPossibleBoards(gb, d, depthToSearch - 1);
                    boardsExplored++;
                }
            }

            return depthTotal / boardsExplored;
        }
        public Direction GetNextMove(IGameBoard board, bool lastMoveResult)
        {
            call++;
            if (call > 4)
                call = 1;

            switch (call)
            {
                case 1:
                    return Direction.Up;

                case 2:
                    return Direction.Left;

                case 3:
                    return Direction.Down;

                case 4:
                    return Direction.Right;

                default:
                    throw new Exception("TILT - Unable to get here, investigate");
            }
        }
        private void AssertPuzzleWithDifficultyHasSpecificNumberOfFields(Difficulty difficulty)
        {
            _gameBoard = _generator.GeneratePuzzle(difficulty);

            Assert.AreEqual(difficulty, _gameBoard.Difficulty);
        }
Example #18
0
 public MoveAction(ITurtle turtle, IGameBoard gameBoard)
 {
     _turtle    = turtle;
     _gameBoard = gameBoard;
 }
 protected override bool MakeMove(IPlayer player, IGameBoard board, IGameMove move)
 {
     move.Lane.MovePiece(board.BearedOff);
     return true;
 }
Example #20
0
 public TrainController(IGameBoard gameBoard)
 {
     _gameBoard = gameBoard;
 }
Example #21
0
 protected abstract void Setup(IGameBoard board);
Example #22
0
 public IGameMove FindBestMove(IGameBoard b)
 {
     return(FindBestMove(b, long.MinValue, long.MaxValue,
                         mMaxDepth, b.CurrentPlayer == 1).Move);
 }
Example #23
0
 public IndexModel(IGameBoard gameBoard)
 {
     _gameBoard = gameBoard;
 }
Example #24
0
 public Track(IGameBoard gameBoard)
 {
     _gameBoard = gameBoard;
 }
Example #25
0
 public GameStateEntity(IGameBoard gameBoard)
 {
     GameBoard = gameBoard;
 }
Example #26
0
 protected abstract IMove GetNextMove_Impl(IGameBoard board);
Example #27
0
 public IMove GetNextMove(IGameBoard board)
 {
     return(GetNextMove_Impl(board));
 }
 // Explicit method implementations. Do not modify these.
 string IConsoleView.BoardToString(IGameBoard board)
 {
     return(BoardToString(board as ChessBoard));
 }
Example #29
0
 public TrainsRenderer(IGameBoard gameBoard, ITrainRenderer trainRenderer, IPixelMapper pixelMapper)
 {
     _gameBoard     = gameBoard;
     _trainRenderer = trainRenderer;
     _pixelMapper   = pixelMapper;
 }
Example #30
0
 public GameService(IGameBoard board, IDeck deck)
 {
     _board = board;
     _deck  = deck;
 }
Example #31
0
 public GamePlay(IGameBoard gameBoard, IPlayerController playerController, IAI aimiamx)
 {
     _gameBoard        = gameBoard ?? throw new ArgumentNullException(nameof(gameBoard));
     _playerController = playerController ?? throw new ArgumentNullException(nameof(playerController));
     _aimiamx          = aimiamx ?? throw new ArgumentNullException(nameof(aimiamx));
 }
Example #32
0
 public TrainTool(IGameBoard gameBoard, ITrainController gameState)
 {
     _gameBoard = gameBoard;
     _gameState = gameState;
 }
Example #33
0
 public TrainsRenderer(IGameBoard gameBoard, IRenderer <Train> trainRenderer)
 {
     _gameBoard     = gameBoard;
     _trainRenderer = trainRenderer;
 }
Example #34
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="gameBoard">ゲーム盤</param>
 /// <param name="field">戦場</param>
 /// <param name="activeArmy">行動する軍</param>
 public MovePhase(IGameBoard gameBoard, Field field, Army activeArmy)
 {
     this.gameBoard  = gameBoard;
     this.field      = field;
     this.activeArmy = activeArmy;
 }
 public void MovePiece(IPlayer player, IGameBoard board, IGameMove move)
 {
     for (var strategy = this; strategy != null && !strategy.MakeMove(player, board, move); strategy = strategy.next)
     {
     }
 }
Example #36
0
 private IList<IGameMove> CallGetStrategyValidMoves(GameRuleStrategyBase strategy, IGameBoard board, ITurn turn, IGameRuleStrategyContext context)
 {
     return strategy.GetStrategyAvailableMoves(board, turn, context)
         .Cast<IGameMove>()
         .ToList();
 }
 public FallingRocksEngine(Dwarf dwarf, IGameBoard gameBoard)
 {
     this.dwarf = dwarf;
     this.gameBoard = gameBoard;
     this.rocks = new List<Rock>();
 }
Example #38
0
 public TrainTool(IGameBoard gameBoard, ILayout <Track> trackLayout, ITrainManager gameState)
 {
     _gameBoard    = gameBoard;
     _trackLayout  = trackLayout;
     _trainManager = gameState;
 }
Example #39
0
 public void ConstructorShouldThrowExceptionWhenArgumentIsNull()
 {
     _gameBoard = new GameBoard(null, Difficulty.Easy);
 }
 public GameBoardViewModel(IGameBoard gameBoard)
 {
     this.gameBoard = gameBoard;
 }
 public Character(IGameBoard gameBoard)
 {
     this.gameBoard = gameBoard;
 }
 public void Setup()
 {
     this.gameboard = A.Fake<IGameBoard>();
     this.testee = new GameBoardViewModel(this.gameboard);
 }
Example #43
0
        public AI(IGameBoardRepository gameBoardRepository, IPlayerReposytory playerReposytory, IGameBoard board)
        {
            _gameBoardRepository = gameBoardRepository;
            _playerRepository    = playerReposytory;
            _gameBoard           = board;

            //_playerX = _playerRepository.LoadNewPlayerList()[0];
            //_playerO = _playerRepository.LoadNewPlayerList()[1];
            _winConstellations = new int[8, 3]
            {
                { 0, 1, 2 }, /* +---+---+---+*/
                { 3, 4, 5 }, /* | 0 | 1 | 2 |*/
                { 6, 7, 8 }, /* +---+---+---+*/
                { 0, 3, 6 }, /* | 3 | 4 | 5 |*/
                { 1, 4, 7 }, /* +---+---+---+*/
                { 2, 5, 8 }, /* | 6 | 7 | 8 |*/
                { 0, 4, 8 }, /* +---+---+---+*/
                { 2, 4, 6 },
            };

            //_boardAreaFineValues = new int[9]
            //{
            //    3, 2, 3,
            //    2, 4, 2,
            //    3, 2, 3
            //};
        }
 public Postava(IGameBoard gameBoard)
 {
     this.character = new Character(gameBoard);
 }
Example #45
0
 public IGameMove FindBestMove(IGameBoard b)
 {
     return(FindBestMove(b, true ? long.MinValue : long.MaxValue, true ? long.MaxValue : long.MinValue, mMaxDepth).Move);
 }
Example #46
0
 public Task PlayTurn(IGameBoard gameBoard)
 {
     return(strategy.PlayTurn(gameBoard, this.mark));
 }
Example #47
0
 protected override IMove GetNextMove_Impl(IGameBoard board)
 {
     throw new InvalidOperationException("Attempt to move when board is filled");
 }
 protected abstract bool MakeMove(IPlayer player, IGameBoard board, IGameMove move);
Example #49
0
 public Game(IGameBoard gameBoard, IEnumerable <IBoardRenderer> boardRenderers, IPixelMapper pixelMapper)
 {
     _gameBoard      = gameBoard;
     _boardRenderers = boardRenderers;
     _pixelMapper    = pixelMapper;
 }
Example #50
0
 public GameMaster(IAgent agent, IGameBoard gameBoard)
 {
     Agent = agent;
     GameBoard = gameBoard;
 }
Example #51
0
 public LeftZigZag(IGameBoard gameBoard) : base(gameBoard)
 {
 }
Example #52
0
 public void Initialize()
 {
     _gameBoard = new PuzzleGenerator().GeneratePuzzle(Difficulty.Easy);
 }
Example #53
0
 public void GameStarted()
 {
     m_gameBoard = m_gameController.IgameBoard;
 }
Example #54
0
 public void ConstructorShouldThrowExceptionWhenArrayIsMoreThan81Elements()
 {
     _gameBoard = new GameBoard(new int[82], Difficulty.Easy);
 }
Example #55
0
 public TunnelRenderer(ITerrainMap terrainMap, ILayout <Track> layout, IGameBoard gameBoard)
 {
     _terrainMap  = terrainMap;
     _trackLayout = layout;
     _gameBoard   = gameBoard;
 }
Example #56
0
        private static MinimaxBestMove FindBestMove(IGameBoard b, int depthLeft, bool maximize, int alpha, int beta)
        {
            // Implement the minimax algorithm.
            // Your first attempt will not use alpha-beta pruning. Once that works,
            // implement the pruning as discussed in the project notes.
            MinimaxBestMove move = new MinimaxBestMove();

            //tree empty
            if (depthLeft == 0 || b.IsFinished)
            {
                move        = new MinimaxBestMove();
                move.Weight = b.Weight;
                move.Move   = null;
                return(move);
            }

            //initializaitons
            int       bestWeight = int.MaxValue;
            IGameMove bestMove   = null;

            if (maximize)
            {
                bestWeight *= -1;
            }

            var possMoves = b.GetPossibleMoves();

            foreach (var possMove in possMoves)
            {
                b.ApplyMove(possMove);
                //return best move
                MinimaxBestMove w = FindBestMove(b, depthLeft - 1, !maximize, alpha, beta);
                b.UndoLastMove();

                //update alpha
                if (maximize && w.Weight > alpha)
                {
                    alpha      = w.Weight;
                    bestWeight = w.Weight;
                    bestMove   = possMove;

                    //return if alpha not less than beta
                    if (alpha >= beta)
                    {
                        w.Weight = beta;
                        w.Move   = bestMove;
                        return(w);
                    }
                }

                //update beta
                else if (!maximize && w.Weight < beta)
                {
                    beta       = w.Weight;
                    bestWeight = w.Weight;
                    bestMove   = possMove;

                    //return if alpha not less than beta
                    if (alpha >= beta)
                    {
                        w.Weight = alpha;
                        w.Move   = bestMove;
                        return(w);
                    }
                }

                move.Weight = bestWeight;
                move.Move   = bestMove;
            }
            return(move);
        }
Example #57
0
 public void SetUp()
 {
     _board            = new GameBoard();
     _gameStatus       = new GameStatus(_board);
     _gameRulesService = new GameRuleService(_gameStatus);
 }