public GameMove Clone() { var move = new GameMove(nextLocation, gameAction, actionTargetName, message); move.actionAuthorName = actionAuthorName; return(move); }
public override GameMove GenerateMove(GameData gameData) { var hasGun = from actor in gameData.actorDataList where actor.Name != name && actor.Items.Contains(Item.Gun) && actor.Hp > 0 select actor; if (hasGun.Count() != 0) { ActorData badGuy = hasGun.First(); return(new GameMove(badGuy.CurrentLocation, GameAction.NormalAttack, badGuy.Name)); } else if (gameData.actorDataList.Count <= 2) { var BadGuyLocation = from actor in gameData.actorDataList where actor.Name != name select actor.CurrentLocation; return(new GameMove(BadGuyLocation.First(), GameAction.NormalAttack, "*punch*")); } if (gameData.generatorHp > 0) { return(new GameMove(Location.Basement, GameAction.RepairGenerator, "I'm workwing werry hawd fwixing twis, owo")); } else if (gameData.gateHp > 0) { return(new GameMove(Location.Exit, GameAction.RepairGate, "*hits gate* owo, I dwid an oopsie woopsie")); } return(new GameMove(GameMove.GetRandomLocation(), GameMove.GetRandomAction())); }
public override GameMove GenerateMove(GameData gameData) { var query = from actor in gameData.actorDataList where actor.Name == name select actor; ActorData myData = query.First(); if (myData.Hp <= 50 && myData.Items.Contains(Item.Medkit)) { return(new GameMove(myData.CurrentLocation, GameAction.UseMedkit, myData.Name)); } else if (!gameData.isMedkitTaken) { return(new GameMove(Location.Bathroom, GameAction.TakeMedkit)); } else if (gameData.gateHp > 0) { return(new GameMove(Location.Exit, GameAction.RepairGate)); } else if (gameData.generatorHp > 0) { return(new GameMove(Location.Basement, GameAction.RepairGenerator)); } else { return(new GameMove(GameMove.GetRandomLocation(), GameMove.GetRandomAction())); } }
static bool ProcessAttack(GameMove gameMove, List <Actor> actors, Actor attacker) { Actor attackTarget = actors.Find(actor => actor.name == gameMove.actionTargetName); if (attackTarget == null) { var otherActorsQuery = from actor in actors where actor.currentLocation == gameMove.nextLocation && actor.hp > 0 && actor != attacker select actor; var result = otherActorsQuery.ToList(); if (result.Count > 0) { attackTarget = result[random.Next(0, result.Count)]; } } if (attackTarget != null) { bool isAttackGood = false; if (gameMove.gameAction == GameAction.NormalAttack) { if (attacker.items.Contains(Item.Gun)) { Console.WriteLine($"BANG! {attacker.name} shoots {attackTarget.name} with a gun!"); attackTarget.hp -= 100; isAttackGood = true; } else { Console.WriteLine($"{attacker.name} punches {attackTarget.name} in the face!"); attackTarget.hp -= 25; isAttackGood = true; } } else if (gameMove.gameAction == GameAction.StabAttack && attacker.isKiller) { Console.WriteLine($"{attackTarget.name} is stabbed by the killer in the shadows."); attackTarget.hp -= 50; isAttackGood = true; } if (attackTarget.hp <= 0) { Console.WriteLine($"{attackTarget.name} has died..."); attacker.items.AddRange(attackTarget.items); attackTarget.items.Clear(); } return(isAttackGood); } else { return(false); } }
public override GameMove GenerateMove(GameData gameData) { var query = from actor in gameData.actorDataList where actor.Name == name select actor; ActorData myData = query.First(); if (myData.Hp < 100 && myData.Items.Contains(Item.Medkit)) { return(new GameMove(myData.CurrentLocation, GameAction.UseMedkit, myData.Name)); } else if (gameData.actorDataList.Count <= 2) { return(new GameMove(GameMove.GetRandomLocation(), GameAction.Attack)); } return(new GameMove(GameMove.GetRandomLocation(), GameMove.GetRandomAction())); }
public override GameMove GenerateMove(GameData gameData) { var myQuery = from actor in gameData.actorDataList where actor.Name == name select actor; ActorData myData = myQuery.First(); var actorsAliveQuery = from actor in gameData.actorDataList where actor.Hp > 0 select actor; if (myData.Hp < 74 && myData.Items.Contains(Item.Medkit)) { return(new GameMove(myData.CurrentLocation, GameAction.UseMedkit, myData.Name, "I feel better.")); } //if (gameData.isSafeUnlocked && !gameData.isGunTaken) //{ // return new GameMove(Location.Armory, GameAction.TakeGun, myData.Name, "I got the gun ! Get behind me, I'll protect you !"); //} //if (!gameData.isMedkitTaken) //{ // return new GameMove(Location.Bathroom, GameAction.TakeMedkit, myData.Name, "I'm the support now, I'll take good care of you !"); //} if (gameData.gateHp > 0) { return(new GameMove(Location.Exit, GameAction.RepairGate, myData.Name, "Let's get out of here !")); } if (gameData.generatorHp > 0) { return(new GameMove(Location.Basement, GameAction.RepairGenerator, myData.Name, "Let there be light !")); } if (actorsAliveQuery.Count() <= 2) { return(new GameMove(GameMove.GetRandomLocation(), GameAction.NormalAttack, "", "I don't wanna die!")); } return(new GameMove(GameMove.GetRandomLocation(), GameMove.GetRandomAction(), "", "Hmm...")); }
public override GameMove GenerateMove(GameData gameData) { var myQuery = from actor in gameData.actorDataList where actor.Name == name select actor; ActorData myData = myQuery.First(); var actorsAliveQuery = from actor in gameData.actorDataList where actor.Hp > 0 select actor; if (myData.Hp < 100 && myData.Items.Contains(Item.Medkit)) { return(new GameMove(myData.CurrentLocation, GameAction.UseMedkit, myData.Name, "I feel better.")); } else if (actorsAliveQuery.Count() <= 2) { return(new GameMove(GameMove.GetRandomLocation(), GameAction.NormalAttack, "", "I don't wanna die!")); } return(new GameMove(GameMove.GetRandomLocation(), GameMove.GetRandomAction(), "", "Hmm...")); }
public override GameMove GenerateMove(GameData gameData) { return(new GameMove(GameMove.GetRandomLocation(), GameAction.StabAttack, "", "My blade thirsts...")); }
static void Main(string[] args) { Actor killer = null; var actors = new List <Actor>(); var actorControllers = new List <ActorController>(); var factories = new List <ActorControllerFactory>() { new FelixControllerFactory("Alice"), new FelixControllerFactory("Bob"), new FelixControllerFactory("Chris"), new FelixControllerFactory("David"), new FelixControllerFactory("Eve"), }; // Create 1 killer and 4 survivors while (actors.Count < 5) { ActorControllerFactory factory = factories[random.Next(0, factories.Count)]; factories.Remove(factory); if (actors.Count == 0) { killer = new Actor(factory.name) { isKiller = true }; actors.Add(killer); actorControllers.Add(factory.CreateKillerController()); } else { int insertionIndex = random.Next(0, actors.Count + 1); actors.Insert(insertionIndex, new Actor(factory.name)); actorControllers.Insert(insertionIndex, factory.CreateSurvivorController()); } } var actorDataQuery = from actor in actors select actor.actorData; var actorDataList = actorDataQuery.ToList(); var gameData = new GameData(actorDataList); GameState gameState = GameState.Ongoing; // Main game loop while (gameState == GameState.Ongoing) { // Generate every actor's move var moves = new List <GameMove>(); for (int i = 0; i < actors.Count; i++) { Actor actor = actors[i]; if (actor.hp <= 0) { continue; } ActorController controller = actorControllers[i]; GameMove move = controller.GenerateMove(gameData.Clone()); move.actionAuthorName = actor.name; moves.Add(move); } // Process all game moves foreach (var move in moves) { Actor activeActor = actors.Find(a => a.name == move.actionAuthorName); if (activeActor.hp <= 0) { continue; } if (ProcessMove(move, actors, gameData)) { if (move.gameAction == GameAction.StabAttack) { move.actionAuthorName = ""; } foreach (var controller in actorControllers) { controller.moveHistory.Add(move.Clone()); } } gameState = GetGameState(gameData, killer); if (gameState != GameState.Ongoing) { break; } } } foreach (var actor in actors) { if (actor.hp > 0 && !actor.isKiller) { Console.WriteLine($"{actor.name} has survived the murder invitation."); } } }
static bool ProcessMove(GameMove gameMove, List <Actor> actors, GameData gameData) { Actor currentActor = actors.Find(a => a.name == gameMove.actionAuthorName); currentActor.currentLocation = gameMove.nextLocation; switch (gameMove.gameAction) { default: case GameAction.Nothing: break; case GameAction.NormalAttack: case GameAction.StabAttack: return(ProcessAttack(gameMove, actors, currentActor)); case GameAction.RepairGenerator: if (currentActor.currentLocation == Location.Basement && gameData.generatorHp > 0) { gameData.generatorHp -= 10; Console.WriteLine($"{currentActor.name} repairs the generator in the basement."); return(true); } break; case GameAction.RepairGate: if (currentActor.currentLocation == Location.Exit && gameData.gateHp > 0) { gameData.gateHp -= 10; Console.WriteLine($"{currentActor.name} repairs the exit gate."); return(true); } break; case GameAction.UnlockSafe: if (currentActor.currentLocation == Location.Armory && !gameData.isSafeUnlocked) { gameData.isSafeUnlocked = true; Console.WriteLine($"{currentActor.name} unlocks the safe containing the gun."); return(true); } break; case GameAction.TakeGun: if (currentActor.currentLocation == Location.Armory && !gameData.isGunTaken && gameData.isSafeUnlocked) { gameData.isGunTaken = true; currentActor.items.Add(Item.Gun); Console.WriteLine($"{currentActor.name} takes the gun in the safe."); return(true); } break; case GameAction.TakeMedkit: if (currentActor.currentLocation == Location.Bathroom && !gameData.isMedkitTaken) { gameData.isMedkitTaken = true; currentActor.items.Add(Item.Medkit); Console.WriteLine($"{currentActor.name} takes the medkit in the bathroom."); return(true); } break; case GameAction.UseMedkit: if (currentActor.items.Contains(Item.Medkit)) { Actor healTarget = actors.Find(actor => actor.name == gameMove.actionTargetName); if (healTarget == null) { var anyActorQuery = from actor in actors where actor.currentLocation == currentActor.currentLocation select actor; var anyActorList = anyActorQuery.ToList(); healTarget = anyActorList[random.Next(0, anyActorList.Count)]; } if (healTarget.currentLocation == currentActor.currentLocation) { currentActor.items.Remove(Item.Medkit); healTarget.hp = 100; Console.WriteLine($"{currentActor.name} heals {healTarget.name} with the medkit!"); return(true); } } break; } return(false); }
public override GameMove GenerateMove(GameData gameData) { var myQuery = from actor in gameData.actorDataList where actor.Name == name select actor; ActorData myData = myQuery.First(); var actorsAliveQuery = from actor in gameData.actorDataList where actor.Hp > 0 select actor; //var actorsItemsQuery = from actor in gameData.actorDataList // where actor.Items.Contains(Item.Gun) || actor.Items.Contains(Item.Medkit) // select actor; //ActorData dangerousActor = null; if (gameData.isSafeUnlocked == false) { return(new GameMove(Location.Armory, GameAction.UnlockSafe, myData.Name, "I opened the safe !")); } if (gameData.isSafeUnlocked && gameData.isGunTaken == false) { return(new GameMove(Location.Armory, GameAction.TakeGun, myData.Name, "I got the gun ! Get behind me, I'll protect you !")); } foreach (var actor in actorsAliveQuery) { if (myData.Items.Contains(Item.Gun) && actor.Name != myData.Name) { return(new GameMove(actor.CurrentLocation, GameAction.NormalAttack, actor.Name, "Take this !")); } else if (actor.Items.Count > 0 && actor.Name != myData.Name) { return(new GameMove(actor.CurrentLocation, GameAction.StabAttack, actor.Name, "I love blood...")); //dangerousActor = actor; } else if (actor.Hp <= 50 && actor.Hp > 0 && actor.Name != myData.Name) { return(new GameMove(actor.CurrentLocation, GameAction.StabAttack, actor.Name, "I love blood...")); } } //if (actorsItemsQuery != null) //{ // ActorData dangerousActor = actorsItemsQuery.First(); //} ActorData survivorActor = actorsAliveQuery.First(); // je voulais faire une liste des actors dangereux if (myData.Hp < 74 && myData.Items.Contains(Item.Medkit)) { return(new GameMove(myData.CurrentLocation, GameAction.UseMedkit, myData.Name, "I feel better.")); } //if (dangerousActor != null) //{ // return new GameMove(dangerousActor.CurrentLocation, GameAction.StabAttack, "", "I need your life..."); //} //if (actorsAliveQuery.ToList()) //{ // return new GameMove(survivorActor.CurrentLocation, GameAction.StabAttack, "", "I need your life..."); //} if (!gameData.isMedkitTaken) { return(new GameMove(Location.Bathroom, GameAction.TakeMedkit, myData.Name, "I'm the support now, I'll take good care of you !")); } return(new GameMove(GameMove.GetRandomLocation(), GameAction.StabAttack, "", "My blade thirsts...")); }
static void ProcessMove(GameMove gameMove, List <Actor> actors, GameData gameData) { Actor currentActor = gameMove.actor; gameMove.actor.currentLocation = gameMove.nextLocation; switch (gameMove.gameAction) { default: case GameAction.Nothing: break; case GameAction.Attack: Actor attackTarget = actors.Find(actor => actor.name == gameMove.actionTarget); if (attackTarget == null) { var otherActorsQuery = from actor in actors where actor.currentLocation == gameMove.nextLocation && actor.hp > 0 && actor != currentActor select actor; var result = otherActorsQuery.ToList(); if (result.Count > 0) { attackTarget = result[random.Next(0, result.Count)]; } } if (attackTarget != null) { if (currentActor.items.Contains(Item.Gun)) { Console.WriteLine($"BANG! {currentActor.name} shoots {attackTarget.name} with a gun!"); attackTarget.hp -= 100; } else { if (currentActor.isKiller) { Console.WriteLine($"{attackTarget.name} is stabbed by the killer in the shadows."); attackTarget.hp -= 50; } else { Console.WriteLine($"{currentActor.name} punches {attackTarget.name} in the face!"); attackTarget.hp -= 50; } } if (attackTarget.hp <= 0) { Console.WriteLine($"{attackTarget.name} has died..."); currentActor.items.AddRange(attackTarget.items); attackTarget.items.Clear(); } } break; case GameAction.RepairGenerator: if (currentActor.currentLocation == Location.Basement && gameData.generatorHp > 0) { gameData.generatorHp -= 25; Console.WriteLine($"{currentActor.name} repairs the generator in the basement."); } break; case GameAction.RepairGate: if (currentActor.currentLocation == Location.Exit && gameData.gateHp > 0) { gameData.gateHp -= 25; Console.WriteLine($"{currentActor.name} repairs the exit gate."); } break; case GameAction.UnlockSafe: if (currentActor.currentLocation == Location.Armory && !gameData.isSafeUnlocked) { gameData.isSafeUnlocked = true; Console.WriteLine($"{currentActor.name} unlocks the safe containing the gun."); } break; case GameAction.TakeGun: if (currentActor.currentLocation == Location.Armory && !gameData.isGunTaken && gameData.isSafeUnlocked) { gameData.isGunTaken = true; currentActor.items.Add(Item.Gun); Console.WriteLine($"{currentActor.name} takes the gun in the safe."); } break; case GameAction.TakeMedkit: if (currentActor.currentLocation == Location.Bathroom && !gameData.isMedkitTaken) { gameData.isMedkitTaken = true; currentActor.items.Add(Item.Medkit); Console.WriteLine($"{currentActor.name} takes the medkit in the bathroom."); } break; case GameAction.UseMedkit: if (currentActor.items.Contains(Item.Medkit)) { Actor healTarget = actors.Find(actor => actor.name == gameMove.actionTarget); if (healTarget == null) { var anyActorQuery = from actor in actors where actor.currentLocation == currentActor.currentLocation select actor; var anyActorList = anyActorQuery.ToList(); healTarget = anyActorList[random.Next(0, anyActorList.Count)]; } if (healTarget.currentLocation == currentActor.currentLocation) { currentActor.items.Remove(Item.Medkit); healTarget.hp = 100; Console.WriteLine($"{currentActor.name} heals {healTarget.name} with the medkit!"); } } break; } }
public override GameMove GenerateMove(GameData gameData) { return(new GameMove(GameMove.GetRandomLocation(), GameAction.Attack)); }
public override GameMove GenerateMove(GameData gameData) { var query = from actor in gameData.actorDataList where actor.Name == name select actor; bool tryStabArmory = false; //var hLQuery = from actor in gameData.actorDataList // where actor.Name != name // where actor.Hp<=50 // where actor.Hp>0 // select actor; var ennemies = from actor in gameData.actorDataList where actor.Name != name select actor; var gunner = from actor in gameData.actorDataList where actor.Items.Contains(Item.Gun) select actor; var medic = from actor in gameData.actorDataList where actor.Items.Contains(Item.Medkit) select actor; int nbLActor = 0; foreach (ActorData a in gameData.actorDataList) { if (a.Hp > 0) { nbLActor++; } } List <GameMove> lastGM = new List <GameMove>(); foreach (GameMove m in moveHistory) { lastGM.Add(m); } ActorData myData = query.First(); ActorData gunOwner = new ActorData(new Actor("")); if (gunner.Count() > 0) { gunOwner = gunner.First(); } ActorData medOwner = null; if (medic.Count() > 0) { medOwner = medic.First(); } var gunLM = from move in lastGM where move.actionAuthorName == gunOwner.Name select move; List <ActorData> ennemiesData = ennemies.ToList(); GameMove gunnerLM = null; if (lastGM.Count > nbLActor) { lastGM.RemoveRange(0, moveHistory.Count - nbLActor); if (gunLM.Count() > 0) { gunnerLM = gunLM.First(); } } { if (myData.Hp <= 50 && myData.Items.Contains(Item.Medkit)) { return(new GameMove(myData.CurrentLocation, GameAction.UseMedkit, myData.Name)); } else if (!gameData.isMedkitTaken) { return(new GameMove(Location.Bathroom, GameAction.TakeMedkit)); } else if (gameData.isSafeUnlocked && !gameData.isGunTaken) { return(new GameMove(Location.Armory, GameAction.TakeGun)); } else if (myData.Items.Contains(Item.Gun)) { if (gameData.generatorHp > 0) { return(new GameMove(Location.Basement, GameAction.StabAttack, GetLTarget(gameData))); } else { return(new GameMove(Location.Exit, GameAction.StabAttack, GetLTarget(gameData))); } } else if (GetFLTarget(gameData) == null) { if (!tryStabArmory) { tryStabArmory = true; return(new GameMove(Location.Armory, GameAction.UnlockSafe)); } else { tryStabArmory = false; return(new GameMove(Location.Armory, GameAction.StabAttack, GetGunOwner(gameData))); } } else if (gameData.generatorHp > 0) { return(new GameMove(Location.Basement, GameAction.StabAttack, GetLTarget(gameData))); } else { return(new GameMove(Location.Exit, GameAction.StabAttack, GetLTarget(gameData))); } } { //if (myData.Hp <= 50 && myData.Items.Contains(Item.Medkit)) //{ // return new GameMove(myData.CurrentLocation, GameAction.UseMedkit, myData.Name); //} //else if (!gameData.isMedkitTaken) //{ // return new GameMove(Location.Bathroom, GameAction.TakeMedkit); //} //else if (gameData.isSafeUnlocked && !gameData.isGunTaken) //{ // return new GameMove(Location.Armory, GameAction.TakeGun); //} //else if(myData.Items.Contains(Item.Gun)) //{ // string baseTarget = GetLTarget(gameData, Location.Basement); // string exitTarget = GetLTarget(gameData, Location.Exit); // string bathTarget = GetLTarget(gameData, Location.Bathroom); // string armTarget = GetLTarget(gameData, Location.Armory); // if(baseTarget!=null) // { // return new GameMove(Location.Basement, GameAction.StabAttack,baseTarget); // } // else if(exitTarget!=null) // { // return new GameMove(Location.Exit, GameAction.StabAttack, exitTarget); // } // else if (armTarget != null) // { // return new GameMove(Location.Armory, GameAction.StabAttack, armTarget); // } // else // { // return new GameMove(Location.Bathroom, GameAction.StabAttack, bathTarget); // } //} //else if(GetFLTarget(gameData)==null) //{ // if(!gameData.isSafeUnlocked) // { // return new GameMove(Location.Armory, GameAction.UnlockSafe); // } // else // { // if(!gameData.isGunTaken) // { // return new GameMove(Location.Armory, GameAction.TakeGun); // } // else // { // return new GameMove(gunnerLM.nextLocation, GameAction.StabAttack, gunnerLM.actionAuthorName); // } // } //} //else //{ // string baseTarget = GetFLTarget(gameData, Location.Basement); // string exitTarget = GetFLTarget(gameData, Location.Exit); // string bathTarget = GetFLTarget(gameData, Location.Bathroom); // string armTarget = GetFLTarget(gameData, Location.Armory); // if (baseTarget != null) // { // return new GameMove(Location.Basement, GameAction.StabAttack, baseTarget); // } // else if (exitTarget != null) // { // return new GameMove(Location.Exit, GameAction.StabAttack, exitTarget); // } // else if (armTarget != null) // { // return new GameMove(Location.Armory, GameAction.StabAttack, armTarget); // } // else if(bathTarget!=null) // { // return new GameMove(Location.Bathroom, GameAction.StabAttack, bathTarget); // } // else // { // baseTarget = GetHLTarget(gameData, Location.Basement); // exitTarget = GetHLTarget(gameData, Location.Exit); // bathTarget = GetHLTarget(gameData, Location.Bathroom); // armTarget = GetHLTarget(gameData, Location.Armory); // if (baseTarget != null) // { // return new GameMove(Location.Basement, GameAction.StabAttack, baseTarget); // } // else if (exitTarget != null) // { // return new GameMove(Location.Exit, GameAction.StabAttack, exitTarget); // } // else if (armTarget != null) // { // return new GameMove(Location.Armory, GameAction.StabAttack, armTarget); // } // else if (bathTarget != null) // { // return new GameMove(Location.Bathroom, GameAction.StabAttack, bathTarget); // } // else // { // baseTarget = GetLTarget(gameData, Location.Basement); // exitTarget = GetLTarget(gameData, Location.Exit); // bathTarget = GetLTarget(gameData, Location.Bathroom); // armTarget = GetLTarget(gameData, Location.Armory); // if (baseTarget != null) // { // return new GameMove(Location.Basement, GameAction.StabAttack, baseTarget); // } // else if (exitTarget != null) // { // return new GameMove(Location.Exit, GameAction.StabAttack, exitTarget); // } // else if (armTarget != null) // { // return new GameMove(Location.Armory, GameAction.StabAttack, armTarget); // } // else // { // return new GameMove(Location.Bathroom, GameAction.StabAttack, bathTarget); // } // } // } //} } }