private bool PosValidate(List <Coord> atkRange) { bool enmyInRange = false; Unit unit = Oponent.GetUnitAt(Target); foreach (Coord cell in atkRange) { if (unit.InUnit(cell)) { enmyInRange = true; break; } } if (!enmyInRange) { ErrorMsg = NO_ENEMIES; return(false); } else if (!atkRange.Contains(Target)) { ErrorMsg = OUT_OF_RANGE; return(false); } return(true); }
public override double Value() { double total = 1; if (Coord.Distance(Target, Oponent.GetCultCenter().Position) < Coord.Distance(AllyPos, Oponent.GetCultCenter().Position)) { total += 2 * (1 + 1.0 / Coord.Distance(AllyPos, Oponent.GetCultCenter().Position)); } ETerrain terrainAtTarget = Boards.TerrainAt(Target); foreach (ETerrain terrain in CurPlayer.GetPawnAt(AllyPos).PositiveTerrains) { if (terrainAtTarget == terrain) { total += 1; break; } } foreach (ABasicPawn enemy in Oponent.GetAttackers()) { if (Coord.Distance(enemy.Position, CurPlayer.GetCultCenter().Position) < BoardConsts.MAX_COL / 2 && Coord.Distance(Target, enemy.Position) < Coord.Distance(AllyPos, enemy.Position)) { total += 3.0 * (1 + 1.0 / Coord.Distance(AllyPos, enemy.Position)); } } return(total); }
private void ProcessOponents() { for (int i = 0; i < oponents.Count; i++) { Oponent oponent = oponents.GetOponent(i); if (oponent.TransCount > 0) { Trans t = oponent.GetTrans(0); GameObject obj = GameObject.Find("Client (" + oponent.Id + ")"); if (obj == null) { // Body controlled by keyboard if (oponent.TransCount == 1) { obj = Instantiate(Resources.Load("Avatar/AvatarNoCam")) as GameObject; } // Body controlled by VR sensors if (oponent.TransCount > 1) { obj = Instantiate(Resources.Load("Avatar/AvatarVRNoCam")) as GameObject; } obj.transform.parent = this.transform; obj.name = "Client (" + oponent.Id + ")"; } for (int j = 0; j < oponent.TransCount; j++) { t = oponent.GetTrans(j); Transform child = obj.transform.FindDeepChild(t.Id); if (child == null) { Debug.Log("Transform " + t.Id + " not found"); continue; } //Debug.Log("Transform: " + t.Id); child.position = t.Pos; child.rotation = t.Rot; } --oponent.TTL; if (oponent.TTL <= 0) { Destroy(obj); } } } for (int i = oponents.Count - 1; i >= 0; i--) { Oponent o = oponents.GetOponent(i); if (o.TTL < 0) { oponents.RemoveOponent(o.Id); } } }
private static void StartFight(string playerUnits, string oponentUnits, string expectedResult) { var player = new Player(playerUnits); var oponent = new Oponent(oponentUnits); var game = new Game(player, oponent); string actualResult = game.GetPlayerBestSequence(); Assert.AreEqual(expectedResult, expectedResult == "+" ? actualResult[0].ToString() : actualResult); }
void OnCollisionEnter(Collision colision) { Oponent op = colision.collider.gameObject.GetComponent <Oponent> (); if (op) { collideWithOponent(op); } }
public IEnumerator StartNewGame(OponentType type1, OponentType type2) { int rnd = UnityEngine.Random.Range(0, 2); player = OponentFactory.Create(type1).Create((TileValue)rnd + 1); computer = OponentFactory.Create(type2).Create((TileValue)2 - rnd); yield return(new WaitUntil(() => player.IsReady)); yield return(new WaitUntil(() => computer.IsReady)); }
void OnCollisionEnter(Collision col) { Oponent op = col.collider.gameObject.GetComponent <Oponent> (); if (op) { op.TakeDamage(damage); } Destroy(this.gameObject); }
void collideWithOponent(Oponent oponent) { oponent.Attack(this); if (health <= 0) { if (onPlayerDeath != null) { onPlayerDeath(this); } } }
// Removed an oponent from the list by id if it exists public void RemoveOponent(int id) { lock (listLock) { Oponent o = oponents.FirstOrDefault <Oponent>(x => x.Id == id); if (o != null) { oponents.Remove(o); } } }
public void InitMyPlayer(int id) { Debug.LogError($"Client: Initing my player {id} {gameObject.name}", gameObject); Oponent oponentRole = id == 0 ? GameManager.instance.player : GameManager.instance.computer; player.Create((TileValue)1 + id); player = oponentRole as OponentLAN; player.inTurn = id == 1; player.player = this; }
IEnumerator OneGameLoop() { OnNewGame(); int turnCount = 0; Logger.Log("Starting the game", LogTheme.gameLoop); GameGrid.instance.LockSlots(); yield return(StartNewGame(oponentType1, oponentType2)); if (multiplayer) { while (multiplayer) { Server.instance.player1.InitMyPlayer(0); Server.instance.player2.InitMyPlayer(1); do { GameGrid.instance.LockSlots(); Logger.Log("Waiting turn", LogTheme.gameDebug); yield return(new WaitUntil(() => /*IsGameOver() || */ Server.instance.localPlayerTurn)); if (IsGameOver()) { Logger.Log("Ending mid game", LogTheme.gameDebug); break; } Logger.Log("Starting turn", LogTheme.gameDebug); GameGrid.instance.UnlockEmptySlots(); yield return(new WaitWhile(() => /*!IsGameOver() ||*/ Server.instance.localPlayerTurn)); } while (!IsGameOver()); Logger.Log("game Ended", LogTheme.gameDebug); OnNewGame(); } } else { GameGrid.instance.UnlockEmptySlots(); Logger.Log("Game starting", LogTheme.gameLoop); currentTurnOponent = player.Value > computer.Value ? player : computer; do { Logger.Log($"{currentTurnOponent.Name}'s turn, this is {++turnCount} turn of the game", LogTheme.gameLoop); currentTurnOponent.MakeTurn(); yield return(new WaitWhile(() => currentTurnOponent.InTurn)); Logger.Log($"{currentTurnOponent.Name} has made a turn", LogTheme.gameLoop); currentTurnOponent = currentTurnOponent == player ? computer : player; } while (!IsGameOver()); } }
// Adds an oponent to the list of oponents if it doesn't already // exist one with the specified id and returns the Oponent object public Oponent AddOponent(int id) { lock (listLock) { Oponent o = oponents.FirstOrDefault <Oponent>(x => x.Id == id); if (o == null) { o = new Oponent(id); oponents.Add(o); } o.TTL = 100; return(o); } }
static void Main(string[] args) { //Console.ReadLine(); // Not needed //var player = new Player(Console.ReadLine()); //Console.ReadLine(); // Not needed //var oponent = new Oponent(Console.ReadLine()); var player = new Player("FPFFP"); var oponent = new Oponent("PFPFPF"); var game = new Game(player, oponent); Console.WriteLine(game.GetPlayerBestSequence()); Console.ReadKey(); }
protected override bool Validate() { bool valid = true; if (!Coord.IsValid(AllyPos) || !Coord.IsValid(Target)) { ErrorMsg = INVALID_POS; valid = false; } else if (Oponent == null) { ErrorMsg = NO_OPONENT; valid = false; } else if (CurPlayer == null) { ErrorMsg = PLAYER; valid = false; } else if (Boards == null) { ErrorMsg = NO_BOARDS; valid = false; } else { APawn allyPawn = CurPlayer.GetPawnAt(AllyPos); if (allyPawn is ABasicPawn) { ABasicPawn allyAttackerPawn = CurPlayer.GetPawnAt(AllyPos) as ABasicPawn; if (allyPawn == null) { ErrorMsg = NO_PAWN; valid = false; } else if (Oponent.GetUnitAt(Target) == null) { ErrorMsg = NO_PAWN; valid = false; } } else { valid = false; } } return(valid); }
public override double Value() { double total = 10; if (Oponent.GetUnitAt(Target) is CulturalCenter) { total += 1.0; } double remainingHealth = Oponent.GetUnitAt(Target).CurrLife / Oponent.GetUnitAt(Target).TotalLife; if (remainingHealth < 0.5) { total += 3.0; } if (Coord.Distance(Target, CurPlayer.GetCultCenter().Position) < BoardConsts.MAX_COL / 2) { total += 1 + 100 / Coord.Distance(Target, CurPlayer.GetCultCenter().Position); } return(total); }
private DuelResult Duel() { while (Player.HasUnits && Oponent.HasUnits || Player.CurrentUnit.IsAlive && Oponent.HasUnits || Oponent.CurrentUnit.IsAlive && Player.HasUnits) { if (Oponent.CurrentUnit == null || !Oponent.CurrentUnit.IsAlive) { Oponent.GetNextUnit(); } if (Player.CurrentUnit == null || !Player.CurrentUnit.IsAlive) { Player.GetNextUnit(); } Fight(Player.CurrentUnit, Oponent.CurrentUnit); } return(DuelResult); }
public string GetPlayerBestSequence() { string sequence = GetNextSequence(); var drawSequence = string.Empty; var victorySequence = string.Empty; while (!string.IsNullOrEmpty(sequence)) { Player.SetUnits(sequence); Player.FinalSequence = string.Empty; Oponent.SetUnits(Oponent.GenuineSequence); // Resets the stack of units DuelResult duelResult = Duel(); if (duelResult == DuelResult.Victory) { victorySequence = Player.FinalSequence; break; } if (duelResult == DuelResult.Draw && string.IsNullOrEmpty(drawSequence)) { drawSequence = Player.FinalSequence; } sequence = GetNextSequence(); } if (!string.IsNullOrEmpty(victorySequence)) { return(string.Concat("+", victorySequence)); } return(!string.IsNullOrEmpty(drawSequence) ? string.Concat("=", drawSequence) : string.Concat("-", Player.GenuineSequence)); }
public override bool Execute(bool isSimulation = false) { bool valid = false; if (Validate()) { ABasicPawn allyPawn = (ABasicPawn)CurPlayer.GetPawnAt(AllyPos); Dijkstra didi = new Dijkstra(Boards.GetBoard(), AllyPos, allyPawn.AtkRange); List <Coord> atkRange = didi.GetValidPaths(Command.ATTACK); if (PosValidate(atkRange)) { valid = true; Unit enemyUnit = Oponent.GetUnitAt(Target); int damage = allyPawn.Atk - enemyUnit.Def; if (damage > 0) { HitMsg = String.Format("{0} HAVE DEALT {1} DAMAGE!", allyPawn.Culture, damage); enemyUnit.CurrLife = enemyUnit.CurrLife - damage; if (enemyUnit.CurrLife <= 0) { Oponent.RemoveUnitAt(Target, Boards); HitMsg += " ENEMY KILLED!!"; } } else { HitMsg = BLOCK; } } } //if (!isSimulation) { // UserUtils.PrintSucess((valid) ? (HitMsg) : (ErrorMsg)); // Console.ReadLine(); //} return(valid); }
public void InsertOponent(Oponent oponent) { m_dataContext.Oponents.InsertOnSubmit(oponent); }
public void UpdateAllGameManagers(GameManager newGameManagerState) { this.player = newGameManagerState.player; this.computer = newGameManagerState.computer; this.currentTurnOponent = newGameManagerState.currentTurnOponent; }
public void FaceOponent() { transform.LookAt(Oponent.Position()); }
private void OnMsgRecv(object sender, Client.ClientMsgEventArgs e) { if (e.Len == 0) { Debug.Log("Disconnected from the server"); online = false; return; } online = true; int dataIndex = 0; Packet packet = PacketBuilder.Parse(e.Buffer, ref dataIndex); // Process the packet switch (packet.Type) { case Packet.PacketType.Text: recvText = ((PacketText)packet).Data; receivedNewText = true; Debug.Log("[S->C]: " + recvText + " (" + packet.Size + " of " + e.Len + " bytes)"); break; case Packet.PacketType.Spawn: spawn = ((PacketSpawn)packet).Data; justSpawned = true; Debug.Log("[S->C]: Spawn Position = " + spawn.Pos + " (" + packet.Size + " of " + e.Len + " bytes)"); break; case Packet.PacketType.OtherClients: var others = ((PacketOtherClients)packet).Data; foreach (var c in others) { // Add or update an oponent by its Id (and restore its TTL) Oponent oponent = oponents.AddOponent(c.Id); for (int i = 0; i < c.TransCount; i++) { oponent.AddTransform(c.GetTrans(i)); } } break; case Packet.PacketType.Objects: List <Trans> objectsRecv = ((PacketObjects)packet).Data; foreach (var o in objectsRecv) { Trans t = objects.Where(x => x.Id == o.Id).FirstOrDefault(); if (t == null) { Debug.Log("Received " + o.Id + " for the first time"); objects.Add(o); } else { t.Pos = o.Pos; t.Rot = o.Rot; } } break; case Packet.PacketType.Benchmark: NetBenchmarks b = ((PacketBenchmark)packet).Data; b.recvTimeStamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds(); Packet p = PacketBuilder.Build(Packet.PacketType.Benchmark, b); client.Send(p.ToArray(), p.Size); break; default: Debug.Assert(false); Debug.LogError("Invalid PacketType" + " (" + packet.Size + " of " + e.Len + " bytes)"); break; } }
public AttackListItem(Oponent oponent) { this.m_oponent = oponent; InitializeComponent(); }
private bool HandleServerPacket(byte[] data, int size) { if (size == 0) { Debug.Log("Disconnected from the server"); return(false); } int dataIndex = 0; // Keep reading while there is data left in the buffer while (dataIndex < size) { // Parse a packet from the data buffer Packet packet = PacketBuilder.Parse(data, ref dataIndex); // Process the packet switch (packet.Type) { case Packet.PacketType.Text: recvText = ((PacketText)packet).Data; receivedNewText = true; Debug.Log("[S->C]: " + recvText + " (" + packet.Size + " of " + size + " bytes)"); break; case Packet.PacketType.Spawn: spawn = ((PacketSpawn)packet).Data; justSpawned = true; Debug.Log("[S->C]: Spawn Position = " + spawn.Pos + " (" + packet.Size + " of " + size + " bytes)"); break; case Packet.PacketType.OtherClients: var others = ((PacketOtherClients)packet).Data; foreach (var c in others) { // Add or update an oponent by its Id (and restore its TTL) Oponent oponent = oponents.AddOponent(c.Id); for (int i = 0; i < c.TransCount; i++) { oponent.AddTransform(c.GetTrans(i)); } } break; case Packet.PacketType.Objects: List <Trans> objectsRecv = ((PacketObjects)packet).Data; foreach (var o in objectsRecv) { Trans t = objects.Where(x => x.Id == o.Id).FirstOrDefault(); if (t == null) { Debug.Log("Received " + o.Id + " for the first time"); objects.Add(o); } else { t.Pos = o.Pos; t.Rot = o.Rot; } } break; case Packet.PacketType.Benchmark: NetBenchmarks b = ((PacketBenchmark)packet).Data; b.recvTimeStamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds(); PacketBuilder.Build(Packet.PacketType.Benchmark, b).Send(socket, new AsyncCallback(SendCallback)); break; default: Debug.Assert(false); Debug.LogError("Invalid PacketType" + " (" + packet.Size + " of " + size + " bytes)"); break; } } return(true); }
public Game(Player player, Oponent oponent) { Player = player; Oponent = oponent; Sequences = new Stack <string>(Swapper.GetAllPermutations(Player.GenuineSequence)); }