public override int ChangePreferredInstrument(GameProperties.Instrument instrument) { int success = base.ChangePreferredInstrument(instrument); if (success != 0) //handle the error in the ui { switch (success) { case 1: warningScreenRef.DisplayPoppup("Marketing is not a playable instrument, it's a skill!"); break; case 2: warningScreenRef.DisplayPoppup("This instrument is already played by someone!"); break; } } else { //enable outline only in this button for (int j = 0; j < UISkillIconsButtons.Count; j++) { Button button = UISkillIconsButtons[j]; button.GetComponent <Outline>().enabled = ((int)instrument == j); } } return(success); }
protected override void InformLevelUpActions(Player invoker, GameProperties.Instrument leveledUpInstrument) { if (didSomeoneDefectedThisRound == false && invoker.GetPlayerType() != GameProperties.PlayerType.TITFORTAT) { didSomeoneDefectedThisRound = (leveledUpInstrument == GameProperties.Instrument.MARKETING); } }
public Player(int id, string name) { this.gameManagerRef = GameGlobals.gameManager; this.id = id; this.name = name; this.tokensBoughtOnCurrRound = 0; this.money = 0; this.numTokens = 0; this.diceRollInstrument = GameProperties.Instrument.NONE; this.preferredInstrument = GameProperties.Instrument.NONE; this.leveledUpInstrument = GameProperties.Instrument.NONE; this.toBeTokenedInstruments = new List <GameProperties.Instrument>(); this.skillSet = new Dictionary <GameProperties.Instrument, int>(); this.albumContributions = new Dictionary <GameProperties.Instrument, int>(); //add values to the dictionary foreach (GameProperties.Instrument instrument in System.Enum.GetValues(typeof(GameProperties.Instrument))) { if (instrument == GameProperties.Instrument.NONE) { continue; } skillSet[instrument] = 0; albumContributions[instrument] = 0; } }
//All AI players pick one of the available instruments similarly //All AI players play for the available instruments similarly protected virtual GameProperties.Instrument ChoosePreferredInstrumentActions(Album currAlbum) { List <GameProperties.Instrument> skillSetKeys = new List <GameProperties.Instrument>(skillSet.Keys); for (int i = (int)likedInstrument; i < skillSetKeys.Count; i = ((i + 1) % skillSetKeys.Count)) { GameProperties.Instrument currInstrument = skillSetKeys[i]; bool instrumentIsAvailable = true; //check if other players have the same preferred instrument foreach (Player player in GameGlobals.players) { if (player == this) { continue; } if (player.GetPreferredInstrument() == currInstrument) { instrumentIsAvailable = false; break; } } if (instrumentIsAvailable) { return(currInstrument); } } return(GameProperties.Instrument.NONE); }
public override int RollTheDice(Player whoRollsTheDice, GameProperties.Instrument diceTarget, int diceNumbers, int rollOrderNumber, int currNumberOfRolls) { //trigger for market if (diceNumbers == 20) { char gameResult = predefinedResults[0]; // if it is the last die to be rolled for market update the prefefinedResults if (rollOrderNumber == currNumberOfRolls - 1) { predefinedResults = predefinedResults.Substring(1); } if (gameResult == 'W') { return(GoodMarketRNG(diceNumbers, currNumberOfRolls)); } else if (gameResult == 'L') { return(BadMarketRNG(diceNumbers, currNumberOfRolls)); } else { return(random.Next(1, diceNumbers + 1)); } } else { return(RollDiceFor6(whoRollsTheDice, diceTarget, diceNumbers, rollOrderNumber, currNumberOfRolls)); } }
private IEnumerator ThinkBeforePlayForInstrument(Album currAlbum, float delay, GameProperties.Instrument diceRollInstrument, bool isSendingResponse) //diceRollInstrument not used in current version, maintained to improve flexibility { yield return(new WaitForSeconds(delay)); if (!isSendingResponse) { if (emotionalModule != null) { //Fatima call emotionalModule.NumDices = skillSet[preferredInstrument]; emotionalModule.Perceive(new Name[] { EventHelper.PropertyChange("State(Game)", "PlayForInstrument", name) }); emotionalModule.Decide(); } diceRollInstrument = PlayforInstrumentActions(currAlbum); playerMonoBehaviourFunctionalities.StartCoroutine(ThinkBeforePlayForInstrument(currAlbum, sendResponsesDelay, diceRollInstrument, true)); } else { playerMonoBehaviourFunctionalities.StartCoroutine(SimulateMouseClick(UIrollForPreferredInstrumentButton, 0.3f)); } }
public override int ChangeDiceRollInstrument(GameProperties.Instrument instrument) { int success = base.ChangeDiceRollInstrument(instrument); if (success != 0) //handle the error in the ui { switch (success) { case 1: warningScreenRef.DisplayPoppup("The dices for marketing are rolled only after knowing the album result."); break; case 2: warningScreenRef.DisplayPoppup("You cannot roll dices for an unevolved skill!"); break; } } else { //enable outline only in this button for (int j = 0; j < UISkillIconsButtons.Count; j++) { Button button = UISkillIconsButtons[j]; button.GetComponent <Outline>().enabled = ((int)instrument == j); } } return(success); }
public void ChoosePreferredInstrumentRequest(Album currAlbum) { //save player state before changes unchangedSkillSetInstruments = new Dictionary <GameProperties.Instrument, int>(); unchangedMoney = money; unchangedNumTokens = numTokens; this.preferredInstrument = GameProperties.Instrument.NONE; ChoosePreferredInstrument(currAlbum); }
public override void InformLevelUp(Player invoker, GameProperties.Instrument leveledUpInstrument) { if (!GameProperties.configurableProperties.isSimulation) { playerMonoBehaviourFunctionalities.StartCoroutine(DelayedInformLevelUpActions(invoker, leveledUpInstrument, informLevelUpDelay, true)); } else { InformLevelUpActions(invoker, leveledUpInstrument); } }
public void PlayerPlayForInstrumentResponse(Player invoker) { GameProperties.Instrument rollDiceInstrument = invoker.GetDiceRollInstrument(); if (rollDiceInstrument != GameProperties.Instrument.NONE) //if there is a roll dice instrument { int newAlbumInstrumentValue = RollDicesForInstrument(invoker, rollDiceInstrument); invoker.SetAlbumContribution(rollDiceInstrument, newAlbumInstrumentValue); currAlbum.SetInstrumentValue(invoker.GetDiceRollInstrument(), newAlbumInstrumentValue); } playForInstrumentResponseReceived = true; }
public virtual int ChangeDiceRollInstrument(GameProperties.Instrument instrument) { if (instrument == GameProperties.Instrument.MARKETING) { return(1); } else if (instrument != GameProperties.Instrument.NONE && skillSet[instrument] == 0) { return(2); } this.diceRollInstrument = instrument; return(0); }
protected override GameProperties.Instrument LevelUpActions(Album currAlbum) { GameProperties.Instrument levelUpInstrument = GameProperties.Instrument.NONE; //if someone defected than defect if (didSomeoneDefectedLastRound) { levelUpInstrument = GameProperties.Instrument.MARKETING; } else //on the other rounds see if album was a fail and play cooperatively, otherwise play for marketing { levelUpInstrument = preferredInstrument; } return(levelUpInstrument); }
protected int RollDiceFor6(Player whoRollsTheDice, GameProperties.Instrument diceTarget, int diceNumbers, int rollOrderNumber, int currNumberOfRolls) { if (rollOrderNumber == 0) //first dart being launched { currIndividualDiceValues.Clear(); //achieve the right value int remainingPlayValue = seriesForDices6[whoRollsTheDice][diceTarget][GameGlobals.currGameRoundId][currNumberOfRolls - 1]; float decimalValueForOneDice = (float)remainingPlayValue / (float)currNumberOfRolls; int valueForOneDice = Mathf.FloorToInt(decimalValueForOneDice); for (int i = 0; i < currNumberOfRolls; i++) { currIndividualDiceValues.Add(valueForOneDice); } int remainder = remainingPlayValue - (valueForOneDice * currNumberOfRolls); for (int i = 0; i < currNumberOfRolls; i++) { if (remainder == 0) { break; } currIndividualDiceValues[i] += 1; remainder -= 1; } //randomize dices values //get increase for (int i = 0; i < currNumberOfRolls; i++) { if (currIndividualDiceValues[i] == 1) { continue; } int randomDice = Random.Range(0, currNumberOfRolls); int remainderIncrease = (6 - currIndividualDiceValues[i]); remainderIncrease = (remainderIncrease < currIndividualDiceValues[randomDice]) ? remainderIncrease : currIndividualDiceValues[randomDice] - 1; int randomDecrease = Random.Range(0, remainderIncrease + 1); currIndividualDiceValues[randomDice] -= randomDecrease; currIndividualDiceValues[i] += randomDecrease; } } return(currIndividualDiceValues[rollOrderNumber]); }
public AIPlayer(GameObject playerUIPrefab, GameObject canvas, MonoBehaviourFunctionalities playerMonoBehaviourFunctionalities, PoppupScreenFunctionalities warningScreenref, int id, string name, bool isSpeechAllowed, GameProperties.Instrument likedInstrument) : base(playerUIPrefab, canvas, playerMonoBehaviourFunctionalities, warningScreenref, id, name) { InitDelays(); this.likedInstrument = likedInstrument; if (!GameProperties.configurableProperties.isSimulation && isSpeechAllowed) { GameObject erp = new GameObject("EmotionalRoboticPlayer"); emotionalModule = erp.AddComponent <EmotionalModule>(); emotionalModule.Speaks = isSpeechAllowed; emotionalModule.ReceiveInvoker(this); //only pass the invoker after it is initialized } this.type = GameProperties.PlayerType.AIPLAYER_NOT_ASSIGNED; }
private IEnumerator ThinkBeforeLevelingUp(Album currAlbum, float delay, GameProperties.Instrument chosenLevelUpInstrument, bool isSendingResponse) { yield return(new WaitForSeconds(delay)); if (!isSendingResponse) { chosenLevelUpInstrument = LevelUpActions(currAlbum); if (emotionalModule != null) { //Fatima call if (chosenLevelUpInstrument == GameProperties.Instrument.MARKETING) { emotionalModule.Perceive(new Name[] { EventHelper.PropertyChange("CurrentPlayer(Name)", name, name), EventHelper.PropertyChange("Action(Game)", "Defect", name), EventHelper.PropertyChange("State(Game)", "LevelUp", name) }); Debug.Log("DEFECT"); } else { emotionalModule.Perceive(new Name[] { EventHelper.PropertyChange("CurrentPlayer(Name)", name, name), EventHelper.PropertyChange("Action(Game)", "Cooperate", name), EventHelper.PropertyChange("State(Game)", "LevelUp", name) }); Debug.Log("COOPERATE"); } emotionalModule.Decide(); } playerMonoBehaviourFunctionalities.StartCoroutine(ThinkBeforeLevelingUp(currAlbum, sendResponsesDelay, chosenLevelUpInstrument, true)); } else { if (chosenLevelUpInstrument == GameProperties.Instrument.MARKETING) { playerMonoBehaviourFunctionalities.StartCoroutine(SimulateMouseClick(UIspendTokenInMarketingButton, 0.3f)); } else { playerMonoBehaviourFunctionalities.StartCoroutine(SimulateMouseClick(UIspendTokenInInstrumentButton, 0.3f)); } } }
protected virtual void InformLevelUpActions(Player invoker, GameProperties.Instrument leveledUpInstrument) { if (emotionalModule != null) { int currSpeakingPlayerId = gameManagerRef.GetCurrSpeakingPlayerId(); if (currSpeakingPlayerId == id && invoker.GetName() == "Player") { Debug.Log(name + ": É a vez do " + invoker.GetName()); emotionalModule.Perceive(new Name[] { EventHelper.PropertyChange("CurrentPlayer(Name)", invoker.GetName(), name), EventHelper.PropertyChange("State(Game)", "LevelUp", name) }); emotionalModule.Decide(); } else if (invoker != this) { emotionalModule.GazeAt(invoker.GetName()); } } }
public override int RollTheDice(Player whoRollsTheDice, GameProperties.Instrument diceTarget, int diceNumbers, int rollOrderNumber, int currNumberOfRolls) { //trigger for market if (diceNumbers == 20) { if (GameGlobals.currGameRoundId < GameProperties.configurableProperties.numberOfAlbumsPerGame - 1) { return(RollDiceFor20(diceNumbers, rollOrderNumber, currNumberOfRolls)); } else { return(BadMarketRNG(diceNumbers, currNumberOfRolls)); } } else { return(RollDiceFor6(whoRollsTheDice, diceTarget, diceNumbers, rollOrderNumber, currNumberOfRolls)); } }
public override int SpendToken(GameProperties.Instrument instrument) { int result = base.SpendToken(instrument); if (result != 0) //handle the error in the UI { switch (result) { case 1: warningScreenRef.DisplayPoppup("You cannot level up more skills in this round!"); break; case 2: warningScreenRef.DisplayPoppup("You cannot develop the same skill more than " + GameProperties.configurableProperties.maximumSkillLevelPerInstrument + " times!"); break; } } return(result); }
public virtual int ChangePreferredInstrument(GameProperties.Instrument instrument) //returns error ids { if (instrument == GameProperties.Instrument.MARKETING) { return(1); } //check if other players have the same preferred instrument foreach (Player player in GameGlobals.players) { if (player == this) { continue; } if (player.preferredInstrument == instrument) { return(2); } } this.preferredInstrument = instrument; return(0); }
public virtual int SpendToken(GameProperties.Instrument instrument) { //cannot spend token on last increased instruments if (numTokens == 0) { return(1); } else if (skillSet[instrument] == GameProperties.configurableProperties.maximumSkillLevelPerInstrument) { return(2); } numTokens--; leveledUpInstrument = instrument; if (!unchangedSkillSetInstruments.ContainsKey(instrument)) { unchangedSkillSetInstruments[instrument] = skillSet[instrument]; } skillSet[instrument]++; GameGlobals.gameLogManager.WriteEventToLog(GameGlobals.currSessionId.ToString(), GameGlobals.currGameId.ToString(), GameGlobals.currGameRoundId.ToString(), this.id.ToString(), this.name, "SPENT_TOKEN", instrument.ToString(), "-"); return(0); }
public int RollDicesForInstrument(Player currPlayer, GameProperties.Instrument instrument) { var skillSet = currPlayer.GetSkillSet(); int newAlbumInstrumentValue = 0; int numTokensForInstrument = skillSet[instrument]; //UI stuff UIRollDiceForInstrumentOverlay.transform.Find("title/Text").GetComponent <Text>().text = currPlayer.GetName() + " rolling " + numTokensForInstrument + " dice for " + instrument.ToString() + " ..."; int[] rolledDiceNumbers = new int[numTokensForInstrument]; //save each rolled dice number to display in the UI for (int i = 0; i < numTokensForInstrument; i++) { int randomIncrease = GameGlobals.gameDiceNG.RollTheDice(currPlayer, instrument, 6, i, numTokensForInstrument); rolledDiceNumbers[i] = randomIncrease; newAlbumInstrumentValue += randomIncrease; } if (!GameProperties.configurableProperties.isSimulation) { string arrowText = ""; if (instrument == GameProperties.Instrument.MARKETING) { arrowText = "+" + newAlbumInstrumentValue * GameProperties.configurableProperties.marketingPointValue + " $"; } else { arrowText = "+ " + newAlbumInstrumentValue + " Album Value"; } StartCoroutine(PlayDiceUIs(currPlayer, newAlbumInstrumentValue, rolledDiceNumbers, 6, dice6UI, "Animations/RollDiceForInstrumentOverlay/dice6/sprites_3/endingAlternatives/", Color.yellow, arrowText, diceRollDelay)); } GameGlobals.gameLogManager.WriteEventToLog(GameGlobals.currSessionId.ToString(), GameGlobals.currGameId.ToString(), GameGlobals.currGameRoundId.ToString(), currPlayer.GetId().ToString(), currPlayer.GetName().ToString(), "ROLLED_INSTRUMENT_DICES", "-", newAlbumInstrumentValue.ToString()); return(newAlbumInstrumentValue); }
public AIPlayerTitForTatStrategy(GameObject playerUIPrefab, GameObject canvas, MonoBehaviourFunctionalities playerMonoBehaviourFunctionalities, PoppupScreenFunctionalities warningScreenref, int id, string name, bool isSpeechAllowed, GameProperties.Instrument likedInstrument) : base(playerUIPrefab, canvas, playerMonoBehaviourFunctionalities, warningScreenref, id, name, isSpeechAllowed, likedInstrument) { this.type = GameProperties.PlayerType.TITFORTAT; didSomeoneDefectedThisRound = false; }
public void SetInstrumentValue(GameProperties.Instrument instrument, int value) { instrumentValues[instrument] = value; UIinstrumentValuesTable.GetComponentsInChildren <Text>()[(int)instrument].text = value.ToString(); this.value = CalcAlbumValue(); }
void SetUpParameterization(GameParameterization parameterization) { GameGlobals.players.Clear(); int currPlayerId = 0; for (int i = 0; i < parameterization.playerParameterizations.Count; i++) { PlayerParameterization currParam = parameterization.playerParameterizations[i]; GameProperties.Instrument currLikedInstrument = GameProperties.Instrument.NONE; switch (currParam.likedInstrument) { case "GUITAR": currLikedInstrument = GameProperties.Instrument.GUITAR; break; case "DRUMS": currLikedInstrument = GameProperties.Instrument.DRUMS; break; case "VOCALS": currLikedInstrument = GameProperties.Instrument.VOCALS; break; case "KEYBOARD": currLikedInstrument = GameProperties.Instrument.KEYBOARD; break; case "BASS": currLikedInstrument = GameProperties.Instrument.BASS; break; default: currLikedInstrument = GameProperties.Instrument.GUITAR; //isErrorEncountered = true; //setupWarningPoppupRef.DisplayPoppup("did not parse the liked instrument of player. Guitar assumed..." + currParam.name); break; } switch (currParam.playerType) { case "HUMAN": GameGlobals.players.Add(new UIPlayer(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name)); break; case "SIMPLE": GameGlobals.players.Add(new AIPlayerSimpleStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument)); break; case "RANDOM": GameGlobals.players.Add(new AIPlayerRandomStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument)); break; case "COOPERATIVE": GameGlobals.players.Add(new AIPlayerCoopStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument)); break; case "GREEDY": GameGlobals.players.Add(new AIPlayerGreedyStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument)); break; case "BALANCED": GameGlobals.players.Add(new AIPlayerBalancedStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument)); break; case "UNBALANCED": GameGlobals.players.Add(new AIPlayerUnbalancedStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument)); break; case "TITFORTAT": GameGlobals.players.Add(new AIPlayerTitForTatStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument)); break; default: isErrorEncountered = true; setupWarningPoppupRef.DisplayPoppup("Error on parsing the player type of " + currParam.name); Debug.Log("[ERROR]: Error on parsing the player type of " + currParam.name); break; } } string pattern = "FIXED:[WL]+"; Match m = Regex.Match(parameterization.ngType, pattern, RegexOptions.IgnoreCase); if (m.Success) { int index = parameterization.ngType.IndexOf(":"); string gameResults = parameterization.ngType.Substring(index + 1); GameGlobals.gameDiceNG = new PredefinedDiceNG(gameResults); } else { switch (parameterization.ngType) { case "RANDOM": GameGlobals.gameDiceNG = new RandomDiceNG(); break; case "FIXED:LOSS": GameGlobals.gameDiceNG = new LossDiceNG(); break; case "FIXED:VICTORY": GameGlobals.gameDiceNG = new VictoryDiceNG(); break; default: isErrorEncountered = true; setupWarningPoppupRef.DisplayPoppup("Error on parsing the NG Type of parameterization " + parameterization.ngType); Debug.Log("[ERROR]: Error on parsing the NG Type of parameterization " + parameterization.ngType); break; } } //Game.gameParameterizations.Add(parameterization); //string json = JsonUtility.ToJson(GameProperties.configurableProperties); }
private IEnumerator ThinkBeforeChoosingPreferredInstrument(Album currAlbum, float delay, GameProperties.Instrument preferredInstrument, bool isSendingResponse) { yield return(new WaitForSeconds(delay)); if (!isSendingResponse) { preferredInstrument = ChoosePreferredInstrumentActions(currAlbum); playerMonoBehaviourFunctionalities.StartCoroutine(ThinkBeforeChoosingPreferredInstrument(currAlbum, sendResponsesDelay, preferredInstrument, true)); } else { playerMonoBehaviourFunctionalities.StartCoroutine(SimulateMouseClick(UISkillIconsButtons[(int)preferredInstrument], 0.3f)); yield return(new WaitForSeconds(1.0f)); //wait before pushing the other button playerMonoBehaviourFunctionalities.StartCoroutine(SimulateMouseClick(UIplayerActionButton, 0.3f)); if (emotionalModule != null) { //Fatima call emotionalModule.Perceive(new Name[] { EventHelper.PropertyChange("Character(Name)", name, name), EventHelper.PropertyChange("Album(Last)", "False", name), EventHelper.PropertyChange("State(Game)", "ChoosePreferredInstrument", name) }); emotionalModule.Decide(); } } }
public abstract void InformLevelUp(Player invoker, GameProperties.Instrument leveledUpInstrument);
private IEnumerator DelayedInformLevelUpActions(Player invoker, GameProperties.Instrument leveledUpInstrument, float delay, bool isInformDelayed) { yield return(new WaitForSeconds(delay)); InformLevelUpActions(invoker, leveledUpInstrument); }
protected override GameProperties.Instrument LevelUpActions(Album currAlbum) { GameProperties.Instrument instrumentToLevelUp = GameProperties.Instrument.NONE; instrumentToLevelUp = (Random.Range(0, 2) > 0) ? preferredInstrument : GameProperties.Instrument.MARKETING; return(instrumentToLevelUp); }
public AIPlayerUnbalancedStrategy(GameObject playerUIPrefab, GameObject canvas, MonoBehaviourFunctionalities playerMonoBehaviourFunctionalities, PoppupScreenFunctionalities warningScreenref, int id, string name, bool isSpeechAllowed, GameProperties.Instrument likedInstrument) : base(playerUIPrefab, canvas, playerMonoBehaviourFunctionalities, warningScreenref, id, name, isSpeechAllowed, likedInstrument) { this.type = GameProperties.PlayerType.UNBALANCED; }
public override void InformLevelUp(Player invoker, GameProperties.Instrument leveledUpInstrument) { }