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; }
internal Builder(IEnumerable <int> rows) { _startingField = new Playground(rows); _validMoves = null; _lastMoveWins = null; _playerCount = null; }
public bool IsMoveValid(Move move, Playground playground) { if (!ValidMoves.Contains(move)) { return(false); } return(!playground.Rows.Where((s, i) => s < move.ChangesPerRow[i]).Any()); }
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); }
/// <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); }
public Node(Playground playground, int moveCount) { Current = playground; Parents = new Node[moveCount]; Children = new Node[moveCount]; }
public List <Move> GetValidMoves(Playground playground) { return(ValidMoves.Where(m => IsMoveValid(m, playground)).ToList()); }
/// <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);
public override Move DecideNextMove(Rules rules, Playground playground) { return(rules.GetValidMoves(playground)[0]); }
public override Move DecideNextMove(Rules rules, Playground playground) { List <Move> validMoves = rules.GetValidMoves(playground); return(validMoves[_random.Next(validMoves.Count)]); }