public virtual void Initialize(GameRunIA game) { var main = game.mains[this.id]; while (main.Count < game.nbDominoMainInitial) { var index = StaticRandom.Next(game.Pioche.Count); var domino = game.Pioche[index]; game.Pioche.RemoveAt(index); main.Add(domino); } FinalizeInitialisation(game); }
private ClassementItem[] SelectPlayers(Dictionary <string, HashSet <string> > playedMatches) { var clsst = Classement.ToArray(); var playersTmp = new ClassementItem[NB_PLAYERS]; int i = 0; int ind = 0; while (playersTmp.Any(x => x == null)) { if (!playersTmp.Any(x => x != null)) { var player1 = classement.OrderBy(x => x.Value.played).First().Value; playersTmp[i] = player1; i++; ind = Array.IndexOf(clsst, player1); } else { var ind2 = StaticRandom.Next(Math.Max(0, ind - 5), Math.Min(100, ind + 5)); var player2 = clsst[ind2]; //var player2 = clsst.OrderBy(p=>p.score- clsst[ind].score) if (!playersTmp.Any(x => x?.pl?.id == player2.pl.id)) { playersTmp[i] = player2; i++; } } } for (int j = 0; j < playersTmp.Length; j++) { classement[playersTmp[j].pl.id].played += 1; } return(playersTmp); }
public override Action NextAction(GameRunIA game) { var main = game.mains[this.id]; // Evaluation des dominos dans la main var leftNum = game.PlayedDominos.First(); var rightNum = game.PlayedDominos.Last(); var possibleDominos = main.Where(d => d.Values.Any(i => i == leftNum || i == rightNum)); // Recupération Action action; Domino playDomino; if (possibleDominos.Any()) { // scoring IA CalculScore(game, possibleDominos, leftNum, rightNum); playDomino = possibleDominos.OrderByDescending(d => d.scores.Max()).First(); main.Remove(playDomino); if (playDomino.scores[0] > playDomino.scores[1]) { if (playDomino.Values[0] == leftNum) { game.PlayedDominos.Insert(0, playDomino.Values[0]); game.PlayedDominos.Insert(0, playDomino.Values[1]); } else { game.PlayedDominos.Add(playDomino.Values[0]); game.PlayedDominos.Add(playDomino.Values[1]); } } else { if (playDomino.Values[1] == leftNum) { game.PlayedDominos.Insert(0, playDomino.Values[1]); game.PlayedDominos.Insert(0, playDomino.Values[0]); } else { game.PlayedDominos.Add(playDomino.Values[1]); game.PlayedDominos.Add(playDomino.Values[0]); } } action = new Action { name = "domino", domino = playDomino }; return(action); } if (game.Pioche.Any()) { var index = StaticRandom.Next(game.Pioche.Count); var domino = game.Pioche[index]; game.Pioche.RemoveAt(index); main.Add(domino); UpdateProbabilite(game, domino); action = new Action { domino = domino, name = "pioche" }; return(action); } action = new Action { name = "passe" }; return(action); }
public override Action NextAction(GameRunIA game) { // Evaluation des dominos dans la main var leftNum = game.PlayedDominos.First(); var rightNum = game.PlayedDominos.Last(); var main = game.mains[this.id]; var possibleLeftDominos = main.Where(d => d.Values.Any(i => i == leftNum)); var possibleRightDominos = main.Where(d => d.Values.Any(i => i == rightNum)); // score = coeff_double*score_double + coeff_div*score_div + coeff_valeur * score_valeur + coeff_bloq * score_bloq // Recupération Domino playDomino; if (possibleLeftDominos.Any()) { // basic IA playDomino = possibleLeftDominos.First(); main.Remove(playDomino); if (playDomino.Values[0] == leftNum) { game.PlayedDominos.Insert(0, playDomino.Values[0]); game.PlayedDominos.Insert(0, playDomino.Values[1]); } else { game.PlayedDominos.Insert(0, playDomino.Values[1]); game.PlayedDominos.Insert(0, playDomino.Values[0]); } return(new Action { name = "domino", domino = playDomino }); } if (possibleRightDominos.Any()) { // basic IA playDomino = possibleRightDominos.First(); main.Remove(playDomino); if (playDomino.Values[0] == rightNum) { game.PlayedDominos.Add(playDomino.Values[0]); game.PlayedDominos.Add(playDomino.Values[1]); } else { game.PlayedDominos.Add(playDomino.Values[1]); game.PlayedDominos.Add(playDomino.Values[0]); } return(new Action { name = "domino", domino = playDomino }); } if (game.Pioche.Any()) { var index = StaticRandom.Next(game.Pioche.Count); var domino = game.Pioche[index]; game.Pioche.RemoveAt(index); main.Add(domino); return(new Action { domino = domino, name = "pioche" }); } return(new Action { name = "passe" }); }