예제 #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
        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
        /// <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
 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)]);
        }