/// <summary> /// Create the window. /// </summary> /// <param name="player">The player this window is for.</param> public PlayerStatus(Player player) { InitializeComponent(); Player = player; if (player == null) return; PlayerGuid = player.Guid; }
/// <summary> /// Called each time the system needs another turn. If you do not return a valid turn, the game will randomly move one of your units. /// This call must return in under 1 second. If it has not returned in 1 second the call will be aborted and a random move will be assigned. /// </summary> /// <param name="map">The game map with all units on it.</param> /// <param name="you">Your player object. This is created for each call.</param> /// <param name="cards">The cards you get to pick from. This does not include locked cards.</param> /// <returns>Your requested turn.</returns> public PlayerTurn Turn(GameMap map, Player you, List<Card> cards) { // get 40 sets, pick the one that's closest to the flag - center of map if flags all done List<Card> best = null; int bestDiff = int.MaxValue; int okDiff = rand.Next(0, 3); FlagState fs = you.FlagStates.FirstOrDefault(fsOn => !fsOn.Touched); Point ptFlag = fs == null ? new Point(map.Width / 2, map.Height / 2) : fs.Position; for (int turnOn = 0; turnOn < 40; turnOn++) { // pick 5 (or fewer if locked) random cards List<Card> moveCards = new List<Card>(); bool[] cardUsed = new bool[cards.Count]; for (int ind = 0; ind < Framework.NUM_PHASES - you.NumLockedCards; ind++) for (int iter = 0; iter < 100; iter++) // in case can't work it with these cards { Trap.trap(iter > 20); int index = rand.Next(cards.Count); if (cardUsed[index]) continue; moveCards.Add(cards[index]); cardUsed[index] = true; break; } // add in the locked cards for (int ind = Framework.NUM_PHASES - you.NumLockedCards; ind < Framework.NUM_PHASES; ind++) moveCards.Add(you.Cards[ind]); // If all we have are rotates, we add in a move forward 1 so that a card that is a turn can then take into account next time we get a forward 1. bool addMove = moveCards.All(card => card.IsRotate); if (addMove) moveCards.Add(new Card(Card.ROBOT_MOVE.FORWARD_ONE, 500)); // run it Utilities.MovePoint mp = Utilities.CardDestination(map, you.Robot.Location, moveCards); // if it kills us we don't want it if (mp.Dead) continue; // if better than before, use it if (addMove) moveCards.RemoveAt(moveCards.Count - 1); int diff = Math.Abs(ptFlag.X - mp.Location.MapPosition.X) + Math.Abs(ptFlag.Y - mp.Location.MapPosition.Y); if (diff <= okDiff) return new PlayerTurn(moveCards, false); if (diff < bestDiff) { bestDiff = diff; best = moveCards; } } return new PlayerTurn(best, false); }
/// <summary> /// A shallow copy constructor. Used when re-ordering players. /// </summary> /// <param name="src">The source layer.</param> /// <param name="archive">The archive square for this player.</param> /// <param name="robot">The robot for this player.</param> /// <param name="spriteColor">The color of this player's sprite.</param> protected Player(Player src, Point archive, Robot robot, Color spriteColor) { Guid = src.Guid; TcpGuid = src.TcpGuid; Password = src.Password; Name = src.Name; Avatar = src.Avatar; Cards = src.Cards; Lives = src.Lives; Damage = src.Damage; Archive = src.Archive; PowerMode = src.PowerMode; FlagStates = new List<FlagState>(src.FlagStates); ServerAllowedArchive = src.ServerAllowedArchive; ServerDealtCards = src.ServerDealtCards; Score = src.Score; Scoreboard = new List<int>(src.Scoreboard); Archive = archive; Robot = robot; SpriteColor = spriteColor; }
public PlayerAI(Player src, Point archive, Robot robot, Color spriteColor) : base(src, archive, robot, spriteColor) { }
private MOVE_RESULT MoveRobot(Player playerOn, MapSquare.DIRECTION dir, Player origPlayer) { Utilities.MovePoint mp = Utilities.Move(MainMap, playerOn.Robot.Location.MapPosition, dir); // if dead, handle that if (mp.Dead) { playerOn.DecreaseLives(); if (playerOn.Mode == Player.MODE.DEAD) { Trace.WriteLine(string.Format("Player {0} has been killed", playerOn.Name)); framework.mainWindow.StatusMessage(string.Format("Player {0} has been killed", playerOn.Name)); } else Trace.WriteLine(string.Format("destroyed - Player {0}, Lives {1}", playerOn.Name, playerOn.Lives)); if (PlaySounds) pitPlayer.Play(); return MOVE_RESULT.DEAD; } // if can't move we're done if (mp.Location.MapPosition == playerOn.Robot.Location.MapPosition) return MOVE_RESULT.STUCK; // if hitting a robot, can we move it? Player plyrMoveRobot = Players.Where(pl => (pl.IsVisible) && (pl.Robot.Location.MapPosition == mp.Location.MapPosition)).FirstOrDefault(); if (plyrMoveRobot != null) { Trace.WriteLine(string.Format(" push - Player: {0} at {1} trying {2} at {3}", playerOn.Name, playerOn.Robot.Location, plyrMoveRobot.Name, plyrMoveRobot.Robot.Location)); if (MoveRobot(plyrMoveRobot, dir, origPlayer) == MOVE_RESULT.STUCK) { Trace.WriteLine(string.Format(" push failed - Player: {0} at {1} blocked by {2} at {3}", playerOn.Name, playerOn.Robot.Location, plyrMoveRobot.Name, plyrMoveRobot.Robot.Location)); ValidateData(); return MOVE_RESULT.STUCK; } origPlayer.Score += 2; if (plyrMoveRobot.Mode == Player.MODE.DEAD || plyrMoveRobot.Mode == Player.MODE.DESTROYED) origPlayer.Score += 5; Trace.WriteLine(string.Format(" push successful - Player: {0} at {1} moved {2} at {3}", playerOn.Name, playerOn.Robot.Location, plyrMoveRobot.Name, plyrMoveRobot.Robot.Location)); ValidateData(); } playerOn.Robot.Location = new BoardLocation(mp.Location.MapPosition, playerOn.Robot.Location.Direction); return MOVE_RESULT.OK; }
private bool FireLaser(BoardLocation location, Player firingPlayer) { LaserMove lm = laserMove[(int) location.Direction]; int x = location.MapPosition.X; int y = location.MapPosition.Y; bool firstSquare = true; bool fired = false; while ((0 <= x) && (x < MainMap.Width) && (0 <= y) && (y < MainMap.Height)) { MapSquare sq = MainMap.Squares[x][y]; // can we move into this square? if ((!firstSquare) && ((sq.Walls & lm.wallEnter) != 0)) break; // robot to hit? (can be us if isLaser is true) Point pt = new Point(x, y); Player plyrTargetRobot = Players.Where(pl => (pl.IsVisible) && (pl.Robot.Location.MapPosition == pt)).FirstOrDefault(); if ((plyrTargetRobot != null) && ((firingPlayer == null) || (!firstSquare))) { // call this before IncreaseDamage because if it's killed it is moved to -1, -1 Explosion expl = new Explosion(framework.frameTicks, plyrTargetRobot.Robot.Location.MapPosition); framework.sprites.Add(expl); framework.laserBeams.Add(new LaserBeam(location.MapPosition, plyrTargetRobot.Robot.Location.MapPosition, firingPlayer == null)); plyrTargetRobot.IncreaseDamage(); fired = true; if (firingPlayer != null) firingPlayer.Score += 1; Trace.WriteLine(string.Format(" laser - Player: {0} at {1} hit by laser at {2}, damage {3}, lives {4}", plyrTargetRobot.Name, plyrTargetRobot.Robot.Location, location, plyrTargetRobot.Damage, plyrTargetRobot.Lives)); if (plyrTargetRobot.Mode == Player.MODE.DEAD) framework.mainWindow.StatusMessage(string.Format("Player {0} has been killed", plyrTargetRobot.Name)); ValidateData(); break; } // can we move out of this square? if ((sq.Walls & lm.wallExit) != 0) break; x += lm.xAdd; y += lm.yAdd; firstSquare = false; } return fired; }
public void PlayerTurn(Player player, List<Card> cards, bool powerDown) { // bugbug - handle timeout, message of who timed out. ValidateData(); // if they aren't on the map (didn't get start position), set it if (player.Robot.Location.IsNull) { player.Robot.Location = new BoardLocation(player.ServerAllowedArchive[0], MapSquare.DIRECTION.NORTH); Trace.WriteLine(string.Format("WARNING: Player {0} did not provide a start location. Using {1}", player.Name, player.Robot.Location)); } // turn this into a validated set of cards. Add random if too few, set with priority, copy over locked. List<Card> playerCards = new List<Card>(); int numLockedCards = player.NumLockedCards; // make sure they selected from the list we gave them List<Card> copyDealt = new List<Card>(player.ServerDealtCards); for (int ind = 0; ind < Framework.NUM_PHASES - numLockedCards; ind++) { if ((ind < cards.Count) && (copyDealt.Contains(cards[ind]))) { playerCards.Add(cards[ind]); copyDealt.Remove(cards[ind]); continue; } Card moveOn = copyDealt[rand.Next(copyDealt.Count - 1)]; playerCards.Add(moveOn); copyDealt.Remove(moveOn); } for (int ind = Framework.NUM_PHASES - numLockedCards; ind < Framework.NUM_PHASES; ind++) if (player.Cards.Count > ind) playerCards.Add(player.Cards[ind]); else Trap.trap(); // should never happen player.Cards = playerCards; if (powerDown) player.AnnouncePowerMode(); StringBuilder buf = new StringBuilder(); foreach (Card plyrCard in playerCards) buf.Append(string.Format("{0}, ", plyrCard)); buf.Remove(buf.Length - 2, 2); Trace.WriteLine(string.Format(" turn - Player: {0}; Cards: {1}{2}", player.Name, buf, player.PowerMode != Player.POWER_MODE.ANNOUNCED ? "" : " - power down announced")); ValidateData(); player.WaitingForReply = Player.COMM_MODE.READY; CheckAllTurnsIn(); }
public void PlayerSetArchive(Player player, BoardLocation location) { player.Robot.Location = location; if (!Players.Any(pl => pl.Robot.Location.IsNull && pl.TcpGuid != null)) phaseOn = PHASE.GET_TURN; }