当前位置: 首页>>代码示例>>C#>>正文


C# GameBoard.GetValidMoves方法代码示例

本文整理汇总了C#中GameBoard.GetValidMoves方法的典型用法代码示例。如果您正苦于以下问题:C# GameBoard.GetValidMoves方法的具体用法?C# GameBoard.GetValidMoves怎么用?C# GameBoard.GetValidMoves使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GameBoard的用法示例。


在下文中一共展示了GameBoard.GetValidMoves方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNextMove

        public GameMove GetNextMove(GameBoard gameBoard, Player player)
        {
            // most naive AI ever
            var random = Core.Utility.Random.New();
            var validTokens = gameBoard.GetTokens()
                                       .Where(x => x.PlayerID == player.ID && x.IsMovable())
                                       .Select(x => new { Token = x, Moves = gameBoard.GetValidMoves(x).ToList() })
                                       .Where(x => x.Moves.Any())
                                       .ToList();
            
            if (!validTokens.Any())
            {
                throw new Exceptions.InvalidMoveException("No available moves for player " + player.Name + ".");
            }

            var token = validTokens[random.Next(validTokens.Count)];
            var point = token.Moves[random.Next(token.Moves.Count)];

            return new GameMove(token.Token, point);
        }
开发者ID:daniel-bytes,项目名称:rps.net,代码行数:20,代码来源:BasicPlayerStrategyV1.cs

示例2: GameBoard_Test_GetValidMoves

        public void GameBoard_Test_GetValidMoves()
        {
            int rows = 3;
            int cols = 3;
            int rowsPerPlayer = 1;
            int bombsPerPlayer = 1;

            var tokens = new List<Token>
                                {
                                    /* 
                                     * |_|F1|_|
                                     * |_|R1|_|
                                     * |_|F2|_|
                                     */
                                    new Token(1, "p1", TokenType.Flag, new Point(0, 1)),
                                    new Token(2, "p1", TokenType.Rock, new Point(1, 1)),
                                    new Token(3, "p2", TokenType.Flag, new Point(2, 1))
                                };

            var playerToken = tokens[1];

            var board = new GameBoard(
                            properties: new GameProperties(new Bounds(rows, cols), rowsPerPlayer, bombsPerPlayer),
                            tokens: tokens);

            var points = board.GetValidMoves(playerToken).OrderBy(x => x.X).ThenBy(x => x.Y).ToList();

            Assert.AreEqual(3, points.Count, "Number of moves should be correct");
            Assert.AreEqual(new Point(1, 0), points[0], "First point should be correct");
            Assert.AreEqual(new Point(1, 2), points[1], "Second point should be correct");
            Assert.AreEqual(new Point(2, 1), points[2], "Third point should be correct");
        }
开发者ID:daniel-bytes,项目名称:rps.net,代码行数:32,代码来源:GameBoardTests.cs


注:本文中的GameBoard.GetValidMoves方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。