public Mod8HanabiPlayer(int playerID, Mod8Settings settings = null) : base(playerID) { NextAction = new HanabiAction(HanabiActionType.Hint, null, -1); Settings = settings ?? new Mod8Settings() { }; }
public void SetActionFromClue(HanabiPlayer cluer, ref HanabiGame game, int clueValue) { int seenvalue = 0; foreach (Mod8HanabiPlayer player in game.Players.Where(p => p != this && p != cluer)) { seenvalue += player.EvaluateHand(ref game).ToMod8Value(); } int personalvalue = PosMod((clueValue - seenvalue), 8); this.NextAction = HanabiAction.FromMod8Value(this, personalvalue); }
public void GeneralLieClue(ref HanabiGame game, Mod8HanabiPlayer player, List <HanabiAction> badactions, int remainingclue) { var badplays = badactions.Select(a => a.Card).ToList(); var plays = player.GetPlayableCards(game).Where(p => badplays.Count(c => c.Number == p.Number && c.Color == p.Color) == 0).ToList(); var ordereddiscards = Logic.OrderedDiscards(game, player); var discards = ordereddiscards.Where(p => badplays.Count(c => c.Number == p.Number && c.Color == p.Color) != 1 || ordereddiscards.Count(c => c.Number == p.Number && c.Color == p.Color) > 1).ToList(); HanabiAction desiredclue = null; if (plays.Count == 0) { desiredclue = new HanabiAction(HanabiActionType.Discard, discards[0], player.Hand.LastIndexOf(discards[0])); } else { desiredclue = new HanabiAction(HanabiActionType.Play, plays[0], player.Hand.IndexOf(plays[0])); } if (badactions.Count > 10) { return; } if (Settings.EnsureProperClues) { int newclue = PosMod(desiredclue.ToMod8Value() + remainingclue, 8); if (IsValidClue(ref game, newclue)) { (game.Players[player.ID] as Mod8HanabiPlayer).NextAction = desiredclue; if (Settings.PrintMoves) { Console.WriteLine($"Player {ID} lied and gave a hint to {desiredclue.Type} { (game.Players[player.ID] as Mod8HanabiPlayer).NextAction.Card}"); } } else { badactions.Add(desiredclue); GeneralLieClue(ref game, player, badactions, remainingclue); } } else { (game.Players[player.ID] as Mod8HanabiPlayer).NextAction = desiredclue; if (Settings.PrintMoves) { Console.WriteLine($"Player {ID} lied and gave a hint to {desiredclue.Type} { (game.Players[player.ID] as Mod8HanabiPlayer).NextAction.Card}"); } } }
public void GiveClue(ref HanabiGame game) { List <HanabiAction> evaluations = new List <HanabiAction>(); foreach (OGMod8HanabiPlayer player in game.Players.Where(p => p != this)) { evaluations.Add(player.EvaluateHand(game)); } int cluevalue = PosMod(evaluations.Select(e => e.ToMod8Value()).Sum(), 8); for (int i = 0; i < game.PlayerCount; i++) { var player = game.Players[i]; if (player != this) { (game.Players[i] as OGMod8HanabiPlayer).SetActionFromClue(this, ref game, cluevalue); } } game.GiveHint(); this.NextAction = new HanabiAction(HanabiActionType.Hint, null, -1); }
/// <summary> /// Called when someone wants to give a clue on their turn. /// </summary> /// <param name="game"></param> public void GiveClue(ref HanabiGame game) { bool cluegiven = false; List <HanabiAction> evaluations = new List <HanabiAction>(); foreach (Mod8HanabiPlayer player in game.Players.Where(p => p != this).OrderBy(p => p.ID)) { evaluations.Add(player.EvaluateHand(ref game)); } int cluevalue = PosMod(evaluations.Select(e => e.ToMod8Value()).Sum(), 8); List <HanabiAction> plays = evaluations.Where(a => a.Type == HanabiActionType.Play).ToList(); if (!IsValidClue(ref game, cluevalue)) { game.BadClues++; if (Settings.EnsureProperClues) { GeneralLieClue(ref game, game.NextPlayer as Mod8HanabiPlayer, plays, PosMod(cluevalue - (game.NextPlayer as Mod8HanabiPlayer).NextAction.ToMod8Value(), 8)); cluegiven = true; } } List <HanabiCard> playcards = new List <HanabiCard>(); for (int i = 0; i < game.PlayerCount; i++) { var player = game.Players[i]; if (player != this) { (game.Players[i] as Mod8HanabiPlayer).SetActionFromClue(this, ref game, cluevalue); } } hints[cluevalue]++; if (Settings.CollisionLying) { var cluedplays = evaluations.Where(a => a.Type == HanabiActionType.Play).Select(a => a.Card).ToList(); var nextplayer = game.NextPlayer as Mod8HanabiPlayer; if (nextplayer.NextAction.Type == HanabiActionType.Play) { var cluedplay = nextplayer.NextAction.Card; foreach (HanabiCard card in cluedplays) { if (cluedplays.Count(c => c.Color == card.Color && c.Number == card.Number) >= 2 && nextplayer.NextAction.Card.Color == card.Color && nextplayer.NextAction.Card.Number == card.Number) { HanabiAction[] bad = { nextplayer.NextAction }; CollisionLieClue(ref game, nextplayer, plays, PosMod(cluevalue - nextplayer.NextAction.ToMod8Value(), 8)); cluegiven = true; break; } } } } if (Settings.PrintMoves && !cluegiven) { Console.WriteLine($"Player {ID} gave a hint."); } //Once the hint has been decided, make sure the game uses up a hint game.GiveHint(); this.NextAction = new HanabiAction(HanabiActionType.Hint, null, -1); }
public OGMod8HanabiPlayer(int playerID) : base(playerID) { NextAction = new HanabiAction(HanabiActionType.Hint, null, -1); ShowPlays = false; }