public CommandShowHand(Player caller, HandZone hand, bool cardsAreFacingUp) { this.caller = caller; this.hand = hand; this.cardsAreFacingUp = cardsAreFacingUp; exCardsAreFacingUp = hand.CardsAreVisibleToOthers; cards = hand.GetCardsInhand().ToArray(); isFacingUps = new bool[cards.Length]; exIsFacingUps = new bool[cards.Length]; for (int i = 0; i < cards.Length; i++) { isFacingUps[i] = cardsAreFacingUp; exIsFacingUps[i] = cards[i].ExIsFacingUp; } }
void SpawnHandAndTable() { //hand.transform.localPosition.Set(0, -2.7f, 0); hand = Instantiate(handPrefab, this.transform); //hand.parent = this.gameObject; hand.ownerNetId = this.netId; hand.zoneName = playerName + "'s hand"; hand.zoneColor = this.playerColor; NetworkServer.Spawn(hand.gameObject); handObject = hand.gameObject; Table = Instantiate(tablePrefab, this.transform); NetworkServer.Spawn(Table.gameObject); tableObject = Table.gameObject; TableEditorDataHolder tableEditorManager = GameObject.FindGameObjectWithTag("TableEditorDataHolder").GetComponent <TableEditorDataHolder>(); tableEditorManager.PlayerTable.SpawnEntities(Table.gameObject, this); }
public void CreateFullInformationGame(List <Card> deck_player1, DeckZone deckzone_player1, HandZone handzone_player1, List <Card> deck_player2, DeckZone deckzone_player2, HandZone handzone_player2) { game.Player1.DeckCards = deck_player1; game.Player1.DeckZone = deckzone_player1; game.Player1.HandZone = handzone_player1; game.Player2.DeckCards = deck_player2; game.Player2.DeckZone = deckzone_player2; game.Player2.HandZone = handzone_player2; }
public static void DisposeHandZoneListener(this IHandZoneListener Listener) { HandZone.DisposeHandZoneListener(Listener); }
public static void RegisterHandZoneListener(this IHandZoneListener Listener) { HandZone.RegisterHandZoneListener(Listener); }
private int getHandCardCount(Controller player) { HandZone handZone = player.HandZone; return(handZone.Count); }
public float SocketEvaluate(Game game) { //int[] features = new int[163]; int count = 0; HandZone Hand = game.CurrentPlayer.HandZone; BoardZone BoardZone = game.CurrentPlayer.BoardZone; BoardZone OpBoardZone = game.CurrentPlayer.Opponent.BoardZone; Minion[] minions = BoardZone.GetAll(); features[count++] = (game.Turn); features[count++] = ((int)game.CurrentPlayer.HeroClass); features[count++] = (game.CurrentPlayer.Hero.Weapon == null ? 0 : game.CurrentPlayer.Hero.Weapon.Card.AssetId); features[count++] = (game.CurrentPlayer.Hero.Weapon == null ? 0 : game.CurrentPlayer.Hero.Weapon.AttackDamage); features[count++] = (game.CurrentPlayer.Hero.Weapon == null ? 0 : game.CurrentPlayer.Hero.Weapon.Durability); features[count++] = (game.CurrentPlayer.Hero.Health); features[count++] = (game.CurrentPlayer.BaseMana); features[count++] = (game.CurrentPlayer.HandZone.Count); features[count++] = (game.CurrentPlayer.DeckZone.Count); features[count++] = (game.CurrentPlayer.BoardZone.Count); for (int i = 0; i < game.CurrentPlayer.HandZone.Count; i++) { features[count++] = (game.CurrentPlayer.HandZone[i].Card.AssetId); } for (int i = 0; i < 10 - game.CurrentPlayer.HandZone.Count; i++) { features[count++] = (0); } foreach (Minion minion in minions) { features[count++] = (minion.Card.AssetId); features[count++] = (minion[GameTag.ATK]); features[count++] = (minion[GameTag.HEALTH]); features[count++] = (minion[GameTag.DAMAGE]); features[count++] = (minion[GameTag.STEALTH]); features[count++] = (minion[GameTag.IMMUNE]); features[count++] = (minion[GameTag.TAUNT]); features[count++] = (minion[GameTag.CANT_BE_TARGETED_BY_SPELLS]); features[count++] = (minion[GameTag.NUM_ATTACKS_THIS_TURN]); features[count++] = (minion.Card.AssetId); } for (int _ = 0; _ < 7 - minions.Length; _++) { features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); } features[count++] = ((int)game.CurrentOpponent.HeroClass); features[count++] = (game.CurrentOpponent.Hero.Weapon == null ? 0 : game.CurrentOpponent.Hero.Weapon.Card.AssetId); features[count++] = (game.CurrentOpponent.Hero.Weapon == null ? 0 : game.CurrentOpponent.Hero.Weapon.AttackDamage); features[count++] = (game.CurrentOpponent.Hero.Weapon == null ? 0 : game.CurrentOpponent.Hero.Weapon.Durability); features[count++] = (game.CurrentOpponent.Hero.Health); features[count++] = (game.CurrentOpponent.BaseMana); features[count++] = (game.CurrentOpponent.HandZone.Count); features[count++] = (game.CurrentOpponent.DeckZone.Count); features[count++] = (game.CurrentOpponent.BoardZone.Count); minions = OpBoardZone.GetAll(); foreach (Minion minion in minions) { features[count++] = (minion.Card.AssetId); features[count++] = (minion[GameTag.ATK]); features[count++] = (minion[GameTag.HEALTH]); features[count++] = (minion[GameTag.DAMAGE]); features[count++] = (minion[GameTag.STEALTH]); features[count++] = (minion[GameTag.IMMUNE]); features[count++] = (minion[GameTag.TAUNT]); features[count++] = (minion[GameTag.CANT_BE_TARGETED_BY_SPELLS]); features[count++] = (minion[GameTag.NUM_ATTACKS_THIS_TURN]); features[count++] = (minion.Card.AssetId); } for (int _ = 0; _ < 7 - minions.Length; _++) { features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); features[count++] = (0); } // Safety check if (count != 169) { Console.WriteLine("ERROR: Incorrect parameter size!"); } for (int i = 0; i < features.Length; i++) { byte[] tmpBytes = BitConverter.GetBytes(features[i]); dataBuffer[4 * i + 0] = tmpBytes[0]; dataBuffer[4 * i + 1] = tmpBytes[1]; dataBuffer[4 * i + 2] = tmpBytes[2]; dataBuffer[4 * i + 3] = tmpBytes[3]; } NNSocket.Send(dataBuffer); NNSocket.Receive(receiveBuffer, 4, SocketFlags.None); return(BitConverter.ToSingle(receiveBuffer)); }
public void OutputCurrentGameForTrainingData(Game game) { List <int> features = new List <int>(); HandZone Hand = game.CurrentPlayer.HandZone; BoardZone BoardZone = game.CurrentPlayer.BoardZone; BoardZone OpBoardZone = game.CurrentPlayer.Opponent.BoardZone; Minion[] minions = BoardZone.GetAll(); features.Add(game.Turn); features.Add((int)game.CurrentPlayer.HeroClass); features.Add(game.CurrentPlayer.Hero.Weapon == null? 0 : game.CurrentPlayer.Hero.Weapon.Card.AssetId); features.Add(game.CurrentPlayer.Hero.Weapon == null? 0 : game.CurrentPlayer.Hero.Weapon.AttackDamage); features.Add(game.CurrentPlayer.Hero.Weapon == null? 0 : game.CurrentPlayer.Hero.Weapon.Durability); features.Add(game.CurrentPlayer.Hero.Health); features.Add(game.CurrentPlayer.BaseMana); features.Add(game.CurrentPlayer.HandZone.Count); features.Add(game.CurrentPlayer.DeckZone.Count); features.Add(game.CurrentPlayer.BoardZone.Count); for (int i = 0; i < game.CurrentPlayer.HandZone.Count; i++) { features.Add(game.CurrentPlayer.HandZone[i].Card.AssetId); } for (int i = 0; i < 10 - game.CurrentPlayer.HandZone.Count; i++) { features.Add(0); } foreach (Minion minion in minions) { features.Add(minion.Card.AssetId); features.Add(minion[GameTag.ATK]); features.Add(minion[GameTag.HEALTH]); features.Add(minion[GameTag.DAMAGE]); features.Add(minion[GameTag.STEALTH]); features.Add(minion[GameTag.IMMUNE]); features.Add(minion[GameTag.TAUNT]); features.Add(minion[GameTag.CANT_BE_TARGETED_BY_SPELLS]); features.Add(minion[GameTag.NUM_ATTACKS_THIS_TURN]); features.Add(minion.Card.AssetId); } for (int _ = 0; _ < 7 - minions.Length; _++) { features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); } features.Add((int)game.CurrentOpponent.HeroClass); features.Add(game.CurrentOpponent.Hero.Weapon == null ? 0 : game.CurrentOpponent.Hero.Weapon.Card.AssetId); features.Add(game.CurrentOpponent.Hero.Weapon == null ? 0 : game.CurrentOpponent.Hero.Weapon.AttackDamage); features.Add(game.CurrentOpponent.Hero.Weapon == null ? 0 : game.CurrentOpponent.Hero.Weapon.Durability); features.Add(game.CurrentOpponent.Hero.Health); features.Add(game.CurrentOpponent.BaseMana); features.Add(game.CurrentOpponent.HandZone.Count); features.Add(game.CurrentOpponent.DeckZone.Count); features.Add(game.CurrentOpponent.BoardZone.Count); minions = OpBoardZone.GetAll(); foreach (Minion minion in minions) { features.Add(minion.Card.AssetId); features.Add(minion[GameTag.ATK]); features.Add(minion[GameTag.HEALTH]); features.Add(minion[GameTag.DAMAGE]); features.Add(minion[GameTag.STEALTH]); features.Add(minion[GameTag.IMMUNE]); features.Add(minion[GameTag.TAUNT]); features.Add(minion[GameTag.CANT_BE_TARGETED_BY_SPELLS]); features.Add(minion[GameTag.NUM_ATTACKS_THIS_TURN]); features.Add(minion.Card.AssetId); } for (int _ = 0; _ < 7 - minions.Length; _++) { features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); features.Add(0); } tmpData.Enqueue(features); }
/// <summary> /// Updates this agent's estimation of the opponent /// </summary> void UpdateOpponent(int handSize) { Opponent.Game = BlindGame; Opponent.Deck = OpponentDeck.Clone(); Opponent.DeckZone = OpponentDeckZone.Clone(Opponent); //OpponentDeckZone.Controller = Opponent; OpponentHandZone = new HandZone(Opponent); //{ // Controller = Opponent //}; foreach (Card card in OpponentDeck) { Entity.FromCard(Opponent, card, null, OpponentDeckZone); } foreach (Card card in PlayedSoFar) { if (OpponentDeckZone.Contains(card)) { OpponentDeckZone.Remove(card); } } for (int i = 0; i < handSize; ++i) { IPlayable rnd = OpponentDeckZone.Random; OpponentDeckZone.Remove(rnd); rnd.Controller = OpponentHandZone.Controller; OpponentHandZone.Add(rnd); } Opponent.HandZone = OpponentHandZone.Clone(Opponent); OpponentGraveyardZone = BlindGame.CurrentOpponent.GraveyardZone.Clone(Opponent); if (BlindGame.CurrentOpponent.SecretZone.Count == 0) { OpponentSecretZone = new SecretZone(Opponent); } else if (BlindGame.CurrentOpponent.SecretZone.Count == 1 && BlindGame.CurrentOpponent.SecretZone.Contains(s => s.IsQuest)) { OpponentSecretZone = BlindGame.CurrentOpponent.SecretZone.Clone(Opponent); } else { OpponentSecretZone = new SecretZone(Opponent); if (!OpponentDeck.Contains(c => c.IsSecret)) { AddBlindSecrets(); } else { var secretsPlayed = OpponentGraveyardZone.Where(p => p.Card.IsSecret).ToList(); if (secretsPlayed != null) { List <string> secrets = GetSecrets(Opponent.HeroClass); foreach (Spell s in secretsPlayed) { if (secretsPlayed.Count(s) > 2) { secrets.Remove(s.Card.Name); } } if (secrets.Count != 0) { AddBlindSecrets(secrets); } else { AddBlindSecrets(GetSecrets(Opponent.HeroClass)); } } } } BlindGame.Player2 = Opponent; BlindGame.CurrentPlayer.Game = BlindGame; BlindGame.CurrentOpponent.Game = BlindGame; }
/// <summary> /// TODO: API /// </summary> /// <param name="oppGame"></param> /// <param name="opponent">the controller of the opponent</param> /// <param name="predicitionMap">the map with all predictions</param> /// <param name="newSimulations"></param> /// <returns></returns> private double simulateOpponentWithPrediction(double lowerTimeBound, double timePerLeaf, POGame.POGame oppGame, Controller opponent, List <Prediction> predicitionMap, ref Dictionary <POGame.POGame, List <MCTSNode> > newSimulations) { double predictionScore = 0; if (predicitionMap?.Any() ?? false) { int denominator = predicitionMap.Count; var scorings = predicitionMap.GroupBy(p => p.Deck.Scoring) .Select(c => new MCTSNode.ScoreExt(((double)c.Count() / denominator), c.Key)) .OrderByDescending(s => s.Value).ToList(); // the simulation time for one prediction double timePerPrediction = timePerLeaf / predicitionMap.Count; // use prediction for each game for (int i = 0; i < predicitionMap.Count; i++) { Prediction prediction = predicitionMap[i]; var setasideZone = opponent.ControlledZones[Zone.SETASIDE] as SetasideZone; setasideZone = new SetasideZone(opponent); // create deck zone List <Card> deckCards = prediction.Deck.Cards; var deckZone = opponent.ControlledZones[Zone.DECK] as DeckZone; deckZone = new DeckZone(opponent); createZone(opponent, deckCards, deckZone, ref setasideZone); deckZone.Shuffle(); // create hand zone List <Card> handCards = prediction.Hand.Cards; var handZone = opponent.ControlledZones[Zone.HAND] as HandZone; handZone = new HandZone(opponent); createZone(opponent, handCards, handZone, ref setasideZone); var oppLeafNodes = new List <MCTSNode>(); IScore oppStrategy = prediction.Deck.Scoring; // forward game POGame.POGame forwardGame = oppGame.getCopy(); // upper time bound for simulation the opponent using the current prediction double oppSimulationTime = lowerTimeBound + (i + 1) * timePerPrediction / 2; // simulate opponent's moves while (forwardGame != null && forwardGame.State == State.RUNNING && forwardGame.CurrentPlayer.Id == opponent.Id) { // simulate var oppRoot = new MCTSNode(opponent.Id, scorings, forwardGame, null, null); MCTSNode bestOppNode = simulate(oppSimulationTime, oppRoot, ref oppLeafNodes); // get solution List <PlayerTask> solutions = bestOppNode.GetSolution(); for (int j = 0; j < solutions.Count && (forwardGame != null); j++) { PlayerTask oppTask = solutions[j]; Dictionary <PlayerTask, POGame.POGame> dir = forwardGame.Simulate(new List <PlayerTask> { oppTask }); forwardGame = dir[oppTask]; if (forwardGame != null && forwardGame.CurrentPlayer.Choice != null) { break; } } } // upper time bound for simulation the player using the forwarded game double simulationTime = oppSimulationTime + timePerPrediction / 2; double score = 0; var leafs = new List <MCTSNode>(); // simulate player using forwarded opponent game while (forwardGame != null && forwardGame.State == State.RUNNING && forwardGame.CurrentPlayer.Id == _playerId) { // simulate var root = new MCTSNode(_playerId, new List <MCTSNode.ScoreExt> { new MCTSNode.ScoreExt(1.0, _scoring) }, forwardGame, null, null); MCTSNode bestNode = simulate(simulationTime, root, ref leafs); // get solution List <PlayerTask> solutions = bestNode.GetSolution(); for (int j = 0; j < solutions.Count && (forwardGame != null); j++) { PlayerTask task = solutions[j]; Dictionary <PlayerTask, POGame.POGame> dir = forwardGame.Simulate(new List <PlayerTask> { task }); forwardGame = dir[task]; if (forwardGame != null && forwardGame.CurrentPlayer.Choice != null) { break; } } // TODO: maybe penalty forwardGame == null score = bestNode.TotalScore; } predictionScore += score; if (forwardGame != null) { newSimulations.Add(forwardGame, leafs); } } } return(predictionScore); }
//Choice cards***can choose a task when you play it private PlayerTask PlayCard(List <PlayerTask> PlayerTaskList, Controller myself, HandZone myHand, BoardZone theBoard, POGame game) { PlayerTask returnTask = null; int maxManaCard = 0; int HighestDamage = 0; int WeaponAttackDamage = 0; //For each valid option, prints all available moves and the cost of the card foreach (PlayerTask task in PlayerTaskList) { if (task.PlayerTaskType == PlayerTaskType.PLAY_CARD) { /*if(task.Target != null){ * Console.WriteLine($"Can Play: {task} Mana: {task.Source.Card.Cost} Target Controller: {task.Target.Controller} Type: {task.Source.Card.Type}"); * } * else{ * Console.WriteLine($"Can Play {task}, {task.Source.Card.Cost} mana. Type: {task.Source.Card.Type}"); * }*/ var cardType = task.Source.Card.Type; if (game.CurrentPlayer.RemainingMana > 0) { if (cardType == CardType.MINION) { //Console.WriteLine(task); //Console.WriteLine($"Entered if statement 0"); if (task.Source.Card.Taunt == true) { //Console.WriteLine($"Entered if statement 1"); if (theBoard.Count() >= 1) { //Console.WriteLine($"Entered if statement 2"); returnTask = task; } } else if (task.Source.Card.Charge == true || task.Source.Card.Rush == true && task.PlayerTaskType == PlayerTaskType.PLAY_CARD && task.Source.Card.Cost >= maxManaCard) { //Adds to the task list because these minions can attack in the same turn //Console.WriteLine($"Entered if statement 3"); maxManaCard = task.Source.Card.Cost; returnTask = task; var mi = new MinionID(); //mi = minion id Minion PlayerMinion = null; Minion OpponentMinion = null; foreach (var x in playerList) { if (x.ToString().Equals(task.Source.ToString())) { PlayerMinion = x; } } int Damage = 0; foreach (var y in opponentList) { if (y.AttackDamage > Damage) { Damage = Damage + y.AttackDamage; OpponentMinion = y; } } mi.playerMinion = PlayerMinion; mi.opponentMinion = OpponentMinion; TurnTaskList.Add(mi); continue; } else { if (task.PlayerTaskType == PlayerTaskType.PLAY_CARD && task.Source.Card.Cost >= maxManaCard) { maxManaCard = task.Source.Card.Cost; returnTask = task; } } } else if (cardType == CardType.SPELL && task.Target != null && task.Target.Controller != myself && task.Target.Health > 0) { //Better way to verify spell target by ID for (int i = 0; i < opponentList.Count(); i++) { if (opponentList[i].Id == task.Target.Id) { returnTask = task; } else if (task.Target.AttackDamage > HighestDamage) { HighestDamage = task.Target.AttackDamage; returnTask = task; } } if (task.Target.Id == game.CurrentOpponent.Hero.Id) { returnTask = task; } continue; } else if (cardType == CardType.WEAPON) { if (task.Source.Card.ATK > WeaponAttackDamage) { WeaponAttackDamage = task.Source.Card.ATK; returnTask = task; } } // can't explicitly target own minions and hero else if (task.Target == null) { maxManaCard = task.Source.Card.Cost; returnTask = task; } } else if (myHand.Count() == 1) { returnTask = task; } else { //Console.WriteLine($"No play card task available"); } } } /*if(returnTask == null){ * Console.WriteLine("Return Playcard task: No card selected"); * } * else{ * Console.WriteLine($"Return PlayCard task: {returnTask}"); * }*/ return(returnTask); }