public static void CheckTrameType(ServerPlayerTrame trame, string headerToCheck) { if (trame.TrameHeader != headerToCheck) { throw new NotExpectedTrameException($"Type of expected trame is {headerToCheck} while received {trame.TrameHeader}"); } }
private void _initGame() { // First trame has already been received outside _initGame() int[,] boardSize = this._trame.TramePayload; ServerPlayerTrame.CheckTrameType(this._trame, "SET"); // We don't need human coordinates to init game this._trame.Receive(); ServerPlayerTrame.CheckTrameType(this._trame, "HUM"); // We get our starting coordinates Coord hmeCoords = new Coord(this._trame.Receive()); ServerPlayerTrame.CheckTrameType(this._trame, "HME"); // We get all information from map int[,] mapInfos = this._trame.Receive(); ServerPlayerTrame.CheckTrameType(this._trame, "MAP"); // We init the game Grid grid = new Grid(); for (int i = 0; i < mapInfos.GetLength(0); i++) { Coord coords = new Coord(mapInfos[i, 0], mapInfos[i, 1]); if (mapInfos[i, this._indexes[Race.HUM]] != 0) { grid.Add(new Pawn(Race.HUM, mapInfos[i, this._indexes[Race.HUM]], coords)); } else { if (hmeCoords.Equals(coords)) { this._indexes[Race.US] = mapInfos[i, 3] != 0 ? 3 : 4; grid.Add(new Pawn(Race.US, mapInfos[i, this._indexes[Race.US]], coords)); } else { this._indexes[Race.THEM] = mapInfos[i, 3] != 0 ? 3 : 4; grid.Add(new Pawn(Race.THEM, mapInfos[i, this._indexes[Race.THEM]], coords)); } } } this._board = new Board(grid, boardSize[1, 0], boardSize[0, 0]); }
public Client(string host, int port) { this._host = host; this._port = port; this._socket = new Socket(SocketType.Stream, ProtocolType.Tcp); this._trame = new ServerPlayerTrame(this._socket); int.TryParse(ConfigurationManager.AppSettings["MinMaxDepthSplit"], out this._depthSplit); int.TryParse(ConfigurationManager.AppSettings["MinMaxDepthNoSplit"], out this._depthNoSplit); this._iaNoSplit = new MinMax(this._depthNoSplit, false); this._iaSplit = new MinMax(this._depthSplit, true); this._indexes = new Dictionary <Race, int>() { { Race.HUM, 2 }, { Race.THEM, 0 }, { Race.US, 0 } }; }