public CardPlayer(CardGame game, bool setToAI, float difficultyModifier = 0) { isAI = setToAI; if (difficultyModifier < 0) { aiDifficultyScale = 0; } else if (difficultyModifier > 1) { aiDifficultyScale = 1; } else { aiDifficultyScale = difficultyModifier; } cardGame = game; playerName = "Player"; maxCardsInHand = 5; averageCardValue = 4; cardGrowthValue = 2; playerHealth = 100; randomCardValueWeight = new int[] {5, 10, 20, 30, 20, 10, 5}; playerHand = new Hand (); randomCardValueTotalWeight = 0; foreach (int value in randomCardValueWeight) { randomCardValueTotalWeight += value; } cardSumSequenceList = new List<CardSumSequence> (); }
public Czary(CardGame _frm) { rekaZaklec = new List<Zaklecie>(); taliaZaklec = new List<Zaklecie>(); odrzuconeZaklecia = new List<Zaklecie>(); this.frm = _frm; generujTalie(); }
private CardPlayer player2; // player2 assumed to be AI #endregion Fields #region Methods private void SetupGame() { cardGame = new CardGame (); if (typeOfPlayer1 == PlayerType.Blind) { player1 = new CardPlayerBlind (cardGame, player1IsAI, 0); } else if (typeOfPlayer1 == PlayerType.Reflect) { player1 = new CardPlayerReflect (cardGame, player1IsAI, 0); } else if (typeOfPlayer1 == PlayerType.Mutation) { player1 = new CardPlayerMutation (cardGame, player1IsAI, 0); } if (typeOfPlayer2 == PlayerType.Blind) { player2 = new CardPlayerBlind(cardGame, player2IsAI, 0); } else if (typeOfPlayer2 == PlayerType.Reflect) { player2 = new CardPlayerReflect (cardGame, player2IsAI, 0); } else if (typeOfPlayer2 == PlayerType.Mutation) { player2 = new CardPlayerMutation (cardGame, player2IsAI, 0); } cardGame.InitializeData (player1, player2); }
public PoleWalki(CardGame _frm) { this.frm = _frm; listaAgresorow = new List<Agresor>(); }
public SinglePlayerGameMode() { this.InitializeComponent(); _game = new CardGame(); }
public void WhenClicked() { List <string> deck = CardGame.GenerateDeckLevel1(); }
public void RunSimulation() { // Each turn, need to check to see if we have enough information to make move using UCB // If we do (movelist.count() == choicenum), and we check the stats of each move // A predictable player is set for the currentplayers idx which wil chose the move determined by // Movelist should be tuple array with each entry a state and a who played it // Its key should be a state and the idx of the player in charge HashSet <Tuple <CardGame, int> > visitedstates = new HashSet <Tuple <CardGame, int> >(); CardGame cg = privategame.Clone(); GameIterator gameIterator = privateiterator.Clone(cg); for (int j = 0; j < numPlayers; j++) { cg.players[j].decision = new RandomPlayer(perspective); } int idxme = cg.currentPlayer.Peek().idx; bool expand = true; bool first = true; // "Playing a simulated game" while (!gameIterator.AdvanceToChoice()) { int idx = cg.currentPlayer.Peek().idx; if (idxme == idx) { List <GameActionCollection> allOptions = gameIterator.BuildOptions(); Tuple <CardGame, int>[] movelist = null; int c = 0; if (expand) { int choicenum = allOptions.Count; Tuple <CardGame, int> deliberator = Tuple.Create <CardGame, int>(cg.Clone(), idx); if (!movestatetree.Keys.Contains(deliberator)) { movestatetree[deliberator] = new Tuple <CardGame, int> [choicenum]; } movelist = movestatetree[deliberator]; //Console.WriteLine("Choice num: " + choicenum + " Movelist Count: " + movelist.Count(s => s != null)); if (movelist.Count(s => s != null) == choicenum) { // USE UCB double bestscore = 0; c = 0; double totalplays = 0; foreach (Tuple <CardGame, int> stateandplay in (movelist)) { totalplays += plays[stateandplay]; } totalplays = Math.Log(totalplays); for (int i = 0; i < movelist.Length; i++) { Tuple <CardGame, int> stateandplay = movelist[i]; double temp = wins[stateandplay] / plays[stateandplay]; temp += Math.Sqrt(2 * totalplays / plays[stateandplay]); if (temp > bestscore) { bestscore = temp; c = i; } } allOptions[c].ExecuteAll(); gameIterator.PopCurrentNode(); } else { c = gameIterator.ProcessChoice(); } } else { c = gameIterator.ProcessChoice(); } CardGame savestate = gameIterator.game.Clone(); // THIS HELPS FIND ORIGINAL MOVE CHOICES if (first) { if (!movestates.Keys.Contains(c)) { movestates[c] = savestate; } first = false; } // Stateandplayer is Tuple with state after move, and the idx of the player who made the move Tuple <CardGame, int> stateandplayer = Tuple.Create <CardGame, int>(savestate, idx); // IF THIS IS THE FIRST SIMULATION WHICH HAS ARRIVED AT THIS STATE:: if (expand && (!plays.Keys.Contains(stateandplayer))) { expand = false; plays[stateandplayer] = 0; wins[stateandplayer] = 0; movelist[c] = stateandplayer; } visitedstates.Add(stateandplayer); } else { gameIterator.ProcessChoice(); } // IF IT ISNT MY MOVE, DONT KEEP ANY DATA } // ProcessScore returns a sorted list // where the winner is rank 0 for either min/max games. var winners = gameIterator.ProcessScore(); double[] inverseRankSum = new double[numPlayers]; int p = 0; foreach (Tuple <int, int> scoreandidx in winners) { inverseRankSum[scoreandidx.Item2] = ((double)1) / (p + 1); p++; } // GO THROUGH VISITED STATES foreach (Tuple <CardGame, int> stateandplayer in visitedstates) { if (plays.Keys.Contains(stateandplayer)) { plays[stateandplayer] += 1; wins[stateandplayer] += inverseRankSum[stateandplayer.Item2]; } } }
public void Awake() { AotHelper.EnsureType <StringEnumConverter>(); AotHelper.Ensure(() => { // ReSharper disable once UseObjectOrCollectionInitializer var cardGame = new CardGame(); cardGame.AllCardsUrl = new Uri(UnityFileMethods.FilePrefix); cardGame.AllCardsUrlPageCount = 1; cardGame.AllCardsUrlPageCountDivisor = 1; cardGame.AllCardsUrlPageCountIdentifier = string.Empty; cardGame.AllCardsUrlPageCountStartIndex = 1; cardGame.AllCardsUrlPageIdentifier = string.Empty; cardGame.AllCardsUrlPostBodyContent = string.Empty; cardGame.AllCardsUrlWrapped = false; cardGame.AllCardsUrlZipped = false; cardGame.AllDecksUrl = new Uri(UnityFileMethods.FilePrefix); cardGame.AllDecksUrlDataIdentifier = string.Empty; cardGame.AllDecksUrlPostBodyContent = string.Empty; cardGame.AllDecksUrlTxtRoot = string.Empty; cardGame.AllSetsUrl = new Uri(UnityFileMethods.FilePrefix); cardGame.AllSetsUrlWrapped = false; cardGame.AllSetsUrlZipped = false; cardGame.AutoUpdate = 1; cardGame.AutoUpdateUrl = new Uri(UnityFileMethods.FilePrefix); cardGame.BannerImageFileType = string.Empty; cardGame.BannerImageUrl = new Uri(UnityFileMethods.FilePrefix); cardGame.CardBackImageFileType = string.Empty; cardGame.CardBackImageUrl = new Uri(UnityFileMethods.FilePrefix); cardGame.CardDataIdentifier = string.Empty; cardGame.CardIdIdentifier = string.Empty; cardGame.CardIdStop = string.Empty; cardGame.CardImageFileType = string.Empty; cardGame.CardImageProperty = string.Empty; cardGame.CardImageUrl = string.Empty; cardGame.CardNameIdentifier = string.Empty; cardGame.CardNameIsUnique = false; cardGame.CardPrimaryProperty = string.Empty; cardGame.CardProperties = new List <PropertyDef>(); cardGame.CardPropertyIdentifier = string.Empty; cardGame.CardSetIdentifier = string.Empty; cardGame.CardSetIsObject = false; cardGame.CardSetNameIdentifier = string.Empty; cardGame.CardSetsInList = false; cardGame.CardSetsInListIsCsv = false; cardGame.CardSize = new Float2(1, 1); cardGame.CgsDeepLink = new Uri(UnityFileMethods.FilePrefix); cardGame.DeckFileAltId = string.Empty; cardGame.DeckFileTxtId = DeckFileTxtId.Id; cardGame.DeckFileType = DeckFileType.Dec; cardGame.DeckUrls = new List <DeckUrl>(); var deckUrl = new DeckUrl(string.Empty, string.Empty, new Uri(UnityFileMethods.FilePrefix)); cardGame.Enums = new List <EnumDef>(); var enumDef = new EnumDef(string.Empty, new Dictionary <string, string>()); cardGame.Extras = new List <ExtraDef>(); var extraDef = new ExtraDef(string.Empty, string.Empty, string.Empty); cardGame.GameBoardCards = new List <GameBoardCard>(); var float2 = new Float2(0f, 0f); var gameBoard = new GameBoard(string.Empty, float2, float2); var gameBoardCard = new GameBoardCard(string.Empty, new List <GameBoard>()); cardGame.GameBoardImageFileType = string.Empty; cardGame.GameBoardUrls = new List <GameBoardUrl>(); var gameBoardUrl = new GameBoardUrl(string.Empty, new Uri(UnityFileMethods.FilePrefix)); cardGame.GamePlayDeckName = string.Empty; cardGame.GameStartHandCount = 1; cardGame.GameStartPointsCount = 1; cardGame.Name = string.Empty; cardGame.PlayMatImageFileType = string.Empty; cardGame.PlayMatImageUrl = new Uri(UnityFileMethods.FilePrefix); cardGame.PlayMatSize = new Float2(1, 1); cardGame.RulesUrl = new Uri(UnityFileMethods.FilePrefix); cardGame.SetCardsIdentifier = string.Empty; cardGame.SetCardsUrlIdentifier = string.Empty; cardGame.SetCodeDefault = string.Empty; cardGame.SetCodeIdentifier = string.Empty; cardGame.SetDataIdentifier = string.Empty; cardGame.SetNameDefault = string.Empty; cardGame.SetNameIdentifier = string.Empty; }); }
/************************************************************************ * Game State Transition Methods ************************************************************************/ private void SetupGame() { cardGame = new CardGame (); player1 = new CardPlayerReflect (cardGame, false); player2 = new CardPlayerMutation (cardGame, true); cardGame.InitializeData (player1, player2); }
public override int MakeAction(JObject possibles, Random rand, int idx) { var items = (JArray)possibles ["items"]; CardGame preserved = CardEngine.CardGame.Instance; var results = new int[items.Count]; for (int item = 0; item < items.Count; ++item) { results [item] = 0; for (int i = 0; i < 20; ++i) { Debug.WriteLine("****Made Switch****"); CardGame cg = preserved.Clone(); var flag = true; foreach (var player in cg.players) { if (flag) { flag = false; player.decision = new PredictablePlayer(); Debug.WriteLine("Predictable player choice set: " + item); ((PredictablePlayer)player.decision).toChoose = item; } else { player.decision = new Players.GeneralPlayer(); } } var cloneContext = ParseEngine.currentIterator.Clone(cg); while (!cloneContext.AdvanceToChoice()) { cloneContext.ProcessChoice(); } var winners = cloneContext.parseoop.ProcessScore(ParseEngine.currentTree.scoring()); for (int j = 0; j < winners.Count; ++j) { if (winners [j].Item2 == 0) { results [item] += j; } } } } //Debug.WriteLine ("***Switch Back***"); CardEngine.CardGame.Instance = preserved; var typeOfGame = ParseEngine.currentTree.scoring().GetChild(2).GetText(); if (typeOfGame == "min") { return(idxOfMinimum(results)); } else { return(idxOfMaximum(results)); } //return rand.Next (0,items.Count); }
public CardSumSequence(CardGame game) { cardList = new List<Card> (); cardGame = game; }