コード例 #1
0
 private Rules(ReadOnlyCollection <Move> moves, Playground field, bool?win, int?players)
 {
     ValidMoves    = moves ?? Default.ValidMoves;
     StartingField = field ?? Default.StartingField;
     LastMoveWins  = win ?? Default.LastMoveWins;
     PlayerCount   = players ?? Default.PlayerCount;
 }
コード例 #2
0
 internal Builder(IEnumerable <int> rows)
 {
     _startingField = new Playground(rows);
     _validMoves    = null;
     _lastMoveWins  = null;
     _playerCount   = null;
 }
コード例 #3
0
        public bool IsMoveValid(Move move, Playground playground)
        {
            if (!ValidMoves.Contains(move))
            {
                return(false);
            }

            return(!playground.Rows.Where((s, i) => s < move.ChangesPerRow[i]).Any());
        }
コード例 #4
0
ファイル: AiPlayerMinMax.cs プロジェクト: SantaClaas/NIM
        public List <Tuple <Move, float, float> > GetChances(Playground current)
        {
            List <Tuple <Move, float, float> > chances = new List <Tuple <Move, float, float> >();

            if (_chances.TryGetValue(current, out MoveChancesPlayground moveChances))
            {
                for (int i = 0; i < Rules.ValidMoves.Count; ++i)
                {
                    if (moveChances.WinChances[i] < 0f)
                    {
                        continue;
                    }

                    chances.Add(new Tuple <Move, float, float>(Rules.ValidMoves[i], moveChances.WinChances[i], moveChances.LooseChances[i]));
                }
            }

            return(chances);
        }
コード例 #5
0
ファイル: AiPlayerMinMax.cs プロジェクト: SantaClaas/NIM
        /// <inheritdoc cref="Player.DecideNextMove"/>
        public override Move DecideNextMove(Rules rules, Playground playground)
        {
            if (_gamePlan is null || rules != _gamePlan.Rules)
            {
                _gamePlan = new GamePlan(rules);
                _gamePlan.Generate();
            }

            Dictionary <Move, float> chances = new Dictionary <Move, float>();

            List <Tuple <Move, float, float> > tuples = _gamePlan.GetChances(playground);

            float weight = Math.Abs(_difficulty);

            foreach ((Move move, float winChance, float looseChance) in tuples)
            {
                chances[move] = (float)_random.NextDouble() * (1f - weight) + (_difficulty < 0 ? looseChance : winChance) * weight;
            }

            List <KeyValuePair <Move, float> > keyValuePairs = chances.OrderBy(p => p.Value).ThenBy(p => p.Key.ChangesPerRow.Sum()).ToList();

            return(keyValuePairs.Last().Key);
        }
コード例 #6
0
ファイル: AiPlayerMinMax.cs プロジェクト: SantaClaas/NIM
 public Node(Playground playground, int moveCount)
 {
     Current  = playground;
     Parents  = new Node[moveCount];
     Children = new Node[moveCount];
 }
コード例 #7
0
 public List <Move> GetValidMoves(Playground playground)
 {
     return(ValidMoves.Where(m => IsMoveValid(m, playground)).ToList());
 }
コード例 #8
0
 /// <summary>
 /// Get the next move based on the given rules and the current game state
 /// </summary>
 /// <param name="rules"></param>
 /// <param name="playground"></param>
 /// <returns></returns>
 public abstract Move DecideNextMove(Rules rules, Playground playground);
コード例 #9
0
ファイル: AiPlayer.cs プロジェクト: SantaClaas/NIM
 public override Move DecideNextMove(Rules rules, Playground playground)
 {
     return(rules.GetValidMoves(playground)[0]);
 }
コード例 #10
0
ファイル: AiPlayer.cs プロジェクト: SantaClaas/NIM
        public override Move DecideNextMove(Rules rules, Playground playground)
        {
            List <Move> validMoves = rules.GetValidMoves(playground);

            return(validMoves[_random.Next(validMoves.Count)]);
        }