public void BoardResult_SerializeTest() { Guid user = Guid.Parse("4C0856A8-BBBF-4F78-8FF9-B7C161F470AC"); var board = new Board2(); board.Vulnerable = Vulnerable.Both; var participant = new Participant(new SeatCollection <string>(new string[4] { "Robo", "", "NewUser", "" })); var newResult = new BoardResult("", board, participant); newResult.Auction = new Auction(board.Vulnerable, board.Dealer); newResult.Auction.Record(Bid.C("3NT")); newResult.Auction.Record(Bid.C("p")); newResult.Auction.Record(Bid.C("p")); newResult.Auction.Record(Bid.C("p")); newResult.Play = new PlaySequence(new Contract("3NT", Seats.South, board.Vulnerable), 13); newResult.Play.Record(Suits.Clubs, Ranks.Seven); var s = new DataContractSerializer(typeof(BoardResult)); var m = new MemoryStream(); s.WriteObject(m, newResult); m.Seek(0, SeekOrigin.Begin); BoardResult r = s.ReadObject(m) as BoardResult; Assert.AreEqual <string>(newResult.TeamName, r.TeamName); }
public static GraphicEntity2 New(GridRect rect, Board2 board) { var ge = new GameObject().AddComponent <GraphicEntity2>(); ge.Initialize(rect, board); return(ge); }
public void Board_WordExistsReturnsTrueIfGivenWordExistsOnBoard() { var boardDefinition = "VALANTUTBOTSTTNECODA,TESISPONYSDYNNEVLREP,TODEPUUALEETEMEEAIAA,BEEUOTPERLDIMEVCNLSL,ARRETEAMIENMHEVFETTA,UIIYDEACACERSTEEPDIA,NEVOETIMTTCOIRETNIRP,TIEROTNUAOEFNODESAEL,YRSLIVERQRDIOTNACEDA,YSOBREPUSAANMPRHLRUC,AGONYCIXOTRUDUNUAERI,YACNIZCILERTAOHUMPUT,TSIPAREHTERAPSMULPGS,STUNODENEPOHHSTATUEI,DNEUAREPOTOSSUPSIRCT,NYTNEMESABUROUNDUNLA,AREPEETSIRUTCNUPUCAT,RACCENTABEMORDNILAPS,TSPUCELBATROPSTUBRAT,SSSSPELTENORRABRATES"; var board = new Board2(boardDefinition, _mockEnglishDictionaryService.Object); Assert.IsTrue(board.WordExists("quietude"), "The word 'quietude' appears on the board."); Assert.IsFalse(board.WordExists("quietudes"), "The word 'quietudes' does not appear on the board."); }
public void Board_ValidationAcceptsValidBoard() { var boardDefinition = "AAA,BBB,CCC"; var board = new Board2(boardDefinition, _mockEnglishDictionaryService.Object); var isValid = board.Validate(out string message); Assert.IsTrue(isValid, "The given board definition is valid."); Assert.AreEqual(message, ""); }
public void Initialize(GridRect rect, Board2 board) { //Debug.Log($"Creating GraphicEntity: {rect}"); this.board = board; this.rect = rect; board.LockTiles(rect, this); var rectParams = board.GridRectToRectParams(rect); animatable = NoteFactory.CreateRect(rectParams); }
public void Board_ValidationRejectsInvalidBoard() { var boardDefinition = "AAA,BB"; var board = new Board2(boardDefinition, _mockEnglishDictionaryService.Object); var isValid = board.Validate(out string message); Assert.IsFalse(isValid, "The given board definition is invalid."); Assert.AreEqual(message, "The given board cannot be defined by a square matrix."); }
public GameMode2State(Game1 game, GraphicsDevice graphicsDevice, ContentManager content, int numberOfPlayers, List <int> chosenTexture, List <Texture2D> textures, List <Keys> jumpKeys, List <Keys> leftKeys, List <Keys> rightKeys, List <Keys> shootKeys) : base(game, graphicsDevice, content) { this.jumpKeys = jumpKeys; this.leftKeys = leftKeys; this.rightKeys = rightKeys; this.shootKeys = shootKeys; GraphicsDeviceManager = Game1.graphics; spriteBatch = new SpriteBatch(graphicsDevice); respawnPositions.Add(new Vector2(64, 64)); respawnPositions.Add(new Vector2(1824, 64)); respawnPositions.Add(new Vector2(64, 928)); respawnPositions.Add(new Vector2(1824, 928)); startingPosition = new Vector2(80, 50); tileTexture = content.Load <Texture2D>("Tiles/TileDark"); Console.WriteLine("Loaded tile texture"); backgroundTexture = content.Load <Texture2D>("Tiles/Background"); Console.WriteLine("Loaded background texture"); flagTexture = content.Load <Texture2D>("Objects/Flag"); Console.WriteLine("Loaded flag texture"); font = content.Load <SpriteFont>("font"); Console.WriteLine("Loaded font"); enemyTexture = content.Load <Texture2D>("Enemies/Crab"); bulletTexture = content.Load <Texture2D>("Objects/Bullet"); board = new Board2(tileTexture, spriteBatch, columns, rows); Console.WriteLine("Loaded board"); flag = new Flag(flagTexture, new Vector2(960, 544), spriteBatch); Console.WriteLine("Loaded flag"); background = new Background(backgroundTexture, spriteBatch, columns, rows); Console.WriteLine("Loaded background"); Console.WriteLine("Number of players: " + numberOfPlayers); for (int i = 0; i < numberOfPlayers; i++) { players.Add(new Player(textures[chosenTexture[i]], respawnPositions[rand.Next(0, respawnPositions.Count)], spriteBatch, bulletTexture, 0)); Console.WriteLine("Loaded player " + (i + 1)); } hud = new HUD(players, content); Song song = content.Load <Song>("Sound/background"); Console.WriteLine("Loaded background music"); win = content.Load <SoundEffect>("Sound/win"); death = content.Load <SoundEffect>("Sound/death"); MediaPlayer.Play(song); MediaPlayer.IsRepeating = true; MediaPlayer.Volume = 0.3f; GameMode2State.currentGameState = this; }
public void Board_FindsLongWordCandidatesIn20x20Matrix() { var boardDefinition = "VALANTUTBOTSTTNECODA,TESISPONYSDYNNEVLREP,TODEPUUALEETEMEEAIAA,BEEUOTPERLDIMEVCNLSL,ARRETEAMIENMHEVFETTA,UIIYDEACACERSTEEPDIA,NEVOETIMTTCOIRETNIRP,TIEROTNUAOEFNODESAEL,YRSLIVERQRDIOTNACEDA,YSOBREPUSAANMPRHLRUC,AGONYCIXOTRUDUNUAERI,YACNIZCILERTAOHUMPUT,TSIPAREHTERAPSMULPGS,STUNODENEPOHHSTATUEI,DNEUAREPOTOSSUPSIRCT,NYTNEMESABUROUNDUNLA,AREPEETSIRUTCNUPUCAT,RACCENTABEMORDNILAPS,TSPUCELBATROPSTUBRAT,SSSSPELTENORRABRATES"; var board = new Board2(boardDefinition, _mockEnglishDictionaryService.Object); var allCandidates = board.GetWordCandidates().ToList(); Assert.IsTrue(allCandidates.Count == 22116, "A 16x16 matrix contains 22116 substrings of length at least 3"); Assert.IsTrue(allCandidates.Contains("SYNOPSIS")); Assert.IsTrue(allCandidates.Contains("QUIETUDE")); Assert.IsTrue(allCandidates.Contains("PALINDROME")); Assert.IsTrue(allCandidates.Contains("UNIFORMITY")); Assert.IsTrue(allCandidates.Contains("DERMATOLOGY")); Assert.IsTrue(allCandidates.Contains("ADMONISHMENT")); Assert.IsTrue(allCandidates.Contains("ARACHNOPHOBIA")); }
public static bool operator !=(Board Board1, Board Board2) { if (Board1.IsValid() == false || Board2.IsValid() == false) { return(false); } if (Board1.Street != Board2.Street) { return(true); } if (Board1.Mask != Board2.Mask) { return(true); } return(false); }
IEnumerator SetupAndLaunch() { yield return(null); var gap = 0.309f; //var gap = 0.1f; var sideLength = CameraHelper.Height / ((1 + gap) * rows + gap); cols = (int)(CameraHelper.Width / ((1 + gap) * sideLength)); board = new Board2(cols, rows, sideLength, gap * sideLength); //Debug.Log($"Creating {rows} rows, {cols} cols"); boardRect = new GridRect(0, 0, cols, rows); blues = new Color[9]; blues[0] = blue.WithAlpha(0); blues[1] = blue.WithAlpha(0.125f); blues[2] = blue.WithAlpha(0.125f * 2); blues[3] = blue.WithAlpha(0.125f * 3); blues[4] = blue.WithAlpha(0.125f * 4); blues[5] = blue.WithAlpha(0.125f * 5); blues[6] = blue.WithAlpha(0.125f * 6); blues[7] = blue.WithAlpha(0.125f * 7); blues[8] = blue; oranges = new Color[9]; oranges[0] = orange.WithAlpha(0); oranges[1] = orange.WithAlpha(0.125f); oranges[2] = orange.WithAlpha(0.125f * 2); oranges[3] = orange.WithAlpha(0.125f * 3); oranges[4] = orange.WithAlpha(0.125f * 4); oranges[5] = orange.WithAlpha(0.125f * 5); oranges[6] = orange.WithAlpha(0.125f * 6); oranges[7] = orange.WithAlpha(0.125f * 7); oranges[8] = orange; //StartCoroutine(Run()); //StartCoroutine(Run2()); //AddRow(); //StartCoroutine(Run()); StartVisualization(); }
public void Board_CompareTest() { var board1 = new Board2(); var board2 = new Board2(); Assert.IsTrue(board1.Equals(board2)); var board3 = new Board2(@"E,Both s 753 h KT53 d T654 c K6 s T984 s AKQJ62 h 842 h AQ7 d AQ d 3 c AQJ7 c 543 s h J96 d K9872 c T982 "); Assert.IsFalse(board1.Equals(board3)); }
public ObjectResult GetValidWords2(string boardDefinition) { var board = new Board2(boardDefinition, _englishDictionaryService); if (!board.Validate(out string validationMessage)) { return(StatusCode(StatusCodes.Status400BadRequest, new ErrorResponse { Message = validationMessage })); } var endTime = DateTime.Now.AddSeconds(allottedNumberOfSeconds); var validWords = new List <string>(); using (board.GetWordCandidates().ToObservable() .TakeUntil(endTime) .Subscribe(s => { if (_englishDictionaryService.IsValidWord(s)) { validWords.Add(s); } })) { Debug.WriteLine($">>> Found {validWords.Count} valid words on the board in the allotted time ({allottedNumberOfSeconds} seconds)."); } var boardDisplay = boardDefinition.Split(new char[] { ',' }).ToList(); return(StatusCode(StatusCodes.Status200OK, new ValidWordsResponse { Board = boardDisplay, Words = validWords.Distinct().OrderBy(w => w).ToList() })); }
public TMBoardResult(TableManagerClient _owner, Board2 board, SeatCollection <string> newParticipants) : base("TMBoardResult." + _owner.seat, board, newParticipants, _owner.EventBus, null) { this.tmc = _owner; }
private void ProcessMessage(string message) { #if syncTrace Log.Trace(2, "Client {1} processing '{0}'", message, seat); #endif if (message == "End of session" || message.StartsWith("NS:") // something new from Bridge Moniteur: session ends with ) { this.EventBus.HandleTournamentStopped(); return; } if (Expected(message)) { try { switch (this.state) { case TableManagerProtocolState.WaitForSeated: this.HandleSeated(); this.ChangeState(TableManagerProtocolState.WaitForTeams, false, false, new string[] { "Teams" }, "{0} ready for teams", this.seat); break; case TableManagerProtocolState.WaitForTeams: this.teamNS = message.Substring(message.IndexOf("N/S : \"") + 7); this.teamNS = teamNS.Substring(0, teamNS.IndexOf("\"")); this.teamEW = message.Substring(message.IndexOf("E/W : \"") + 7); this.teamEW = teamEW.Substring(0, teamEW.IndexOf("\"")); if (this.team != (this.seat.IsSameDirection(Seats.North) ? this.teamNS : this.teamEW)) { throw new ArgumentOutOfRangeException("team", "Seated in another team"); } this.HandleTeams(teamNS, teamEW); this.ChangeState(TableManagerProtocolState.WaitForStartOfBoard, false, false, new string[] { "Start of board", "End of session" }, "{0} ready to start", this.seat); break; case TableManagerProtocolState.WaitForStartOfBoard: if (message.StartsWith("Teams")) { // bug in BridgeMoniteur when tournament is restarted } else if (message.StartsWith("Timing")) { // Timing - N/S : this board [minutes:seconds], total [hours:minutes:seconds]. E/W : this board [minutes:seconds], total [hours:minutes:seconds]". // Bridge Moniteur does not send the '.' at the end of the message // Timing - N/S : this board 01:36, total 0:01:36. E/W : this board 01:34, total 0:01:34 if (!message.EndsWith(".")) { message += "."; } string[] timing = message.Split('.'); string[] parts = timing[0].Split(','); string boardNS = "00:" + parts[0].Substring(parts[0].IndexOf("board") + 6).Trim(); string totalNS = parts[1].Substring(parts[1].IndexOf("total") + 6).Trim(); parts = timing[1].Split(','); string boardEW = "00:" + parts[0].Substring(parts[0].IndexOf("board") + 6).Trim(); string totalEW = parts[1].Substring(parts[1].IndexOf("total") + 6).Trim(); TimeSpan _boardNS = ParseTimeUsed(boardNS); TimeSpan _totalNS = ParseTimeUsed(totalNS); TimeSpan _boardEW = ParseTimeUsed(boardEW); TimeSpan _totalEW = ParseTimeUsed(totalEW); this.EventBus.HandleTimeUsed(_boardNS, _totalNS, _boardEW, _totalEW); } else { this.ChangeState(TableManagerProtocolState.WaitForBoardInfo, false, false, new string[] { "Board number" }, "{0} ready for deal", this.seat); } break; case TableManagerProtocolState.WaitForBoardInfo: // "Board number 1. Dealer North. Neither vulnerable." string[] dealInfoParts = message.Split('.'); int boardNumber = Convert.ToInt32(dealInfoParts[0].Substring(13)); this.theDealer = SeatsExtensions.FromXML(dealInfoParts[1].Substring(8)); Vulnerable vulnerability = Vulnerable.Neither; switch (dealInfoParts[2].Substring(1)) { case "Both vulnerable": vulnerability = Vulnerable.Both; break; case "N/S vulnerable": vulnerability = Vulnerable.NS; break; case "E/W vulnerable": vulnerability = Vulnerable.EW; break; } var board = new Board2(this.theDealer, vulnerability, new Distribution()); this.CurrentResult = new TMBoardResult(this, board, new SeatCollection <string>(new string[] { this.teamNS, this.teamEW, this.teamNS, this.teamEW })); this.EventBus.HandleBoardStarted(boardNumber, this.theDealer, vulnerability); this.ChangeState(TableManagerProtocolState.WaitForMyCards, false, false, new string[] { this.seat + "'s cards : " }, "{0} ready for cards", this.seat); break; case TableManagerProtocolState.WaitForMyCards: // "North's cards : S J 8 5.H A K T 8.D 7 6.C A K T 3." // "North's cards : S J 8 5.H A K T 8.D.C A K T 7 6 3." // "North's cards : S -.H A K T 8 4 3 2.D.C A K T 7 6 3." string cardInfo = message.Substring(2 + message.IndexOf(":")); string[] suitInfo = cardInfo.Split('.'); for (int s1 = 0; s1 < 4; s1++) { suitInfo[s1] = suitInfo[s1].Trim(); Suits s = SuitHelper.FromXML(suitInfo[s1].Substring(0, 1)); if (suitInfo[s1].Length > 2) { string cardsInSuit = suitInfo[s1].Substring(2) + " "; if (cardsInSuit.Substring(0, 1) != "-") { while (cardsInSuit.Length > 1) { Ranks rank = Rank.From(cardsInSuit.Substring(0, 1)); this.EventBus.HandleCardPosition(this.seat, s, rank); cardsInSuit = cardsInSuit.Substring(2); } } } } //this.EventBus.WaitForEventCompletion(); // TM is now expecting a response: either a bid or a 'ready for bid' this.EventBus.HandleCardDealingEnded(); break; case TableManagerProtocolState.WaitForOtherBid: if (message.StartsWith("Explain ")) { message = message.Substring(8); string[] answer = message.Split(' '); Seats bidder = SeatsExtensions.FromXML(answer[0]); var bid = new Bid(answer[answer.Length - 1], ""); this.EventBus.HandleExplanationNeeded(bidder, bid); } else { this.WaitForBridgeEvents = true; ProtocolHelper.HandleProtocolBid(message, this.EventBus); } break; case TableManagerProtocolState.WaitForDummiesCards: //Log.Trace("Client {1} processing dummies cards", message, seat); string dummiesCards = message.Substring(2 + message.IndexOf(":")); string[] suitInfo2 = dummiesCards.Split('.'); for (Suits s = Suits.Spades; s >= Suits.Clubs; s--) { int suit = 3 - (int)s; suitInfo2[suit] = suitInfo2[suit].Trim(); if (suitInfo2[suit].Length > 2) { string cardsInSuit = suitInfo2[suit].Substring(2) + " "; if (cardsInSuit.Substring(0, 1) != "-") { while (cardsInSuit.Length > 1) { Ranks rank = Rank.From(cardsInSuit.Substring(0, 1)); this.EventBus.HandleCardPosition(this.CurrentResult.Play.Dummy, s, rank); cardsInSuit = cardsInSuit.Substring(2); } } } } this.WaitForProtocolSync = false; this.EventBus.HandleShowDummy(this.CurrentResult.Play.Dummy); break; case TableManagerProtocolState.WaitForLead: this.WaitForProtocolSync = false; break; case TableManagerProtocolState.WaitForCardPlay: if (message.Contains("to lead")) { /// This indicates a timing issue: TM sent a '... to lead' message before TD sent its HandleTrickFinished event /// Wait until I receveive the HandleTrickFinished event Log.Trace(1, "TableManagerClient.ProcessMessage {0}: received 'to lead' before HandleTrickFinished", this.seat); //Debugger.Break(); } else { string[] cardPlay = message.Split(' '); Seats player = SeatsExtensions.FromXML(cardPlay[0]); Card card = new Card(SuitHelper.FromXML(cardPlay[2].Substring(1, 1)), Rank.From(cardPlay[2].Substring(0, 1))); if (player != this.CurrentResult.Play.Dummy) { this.EventBus.HandleCardPosition(player, card.Suit, card.Rank); } this.WaitForBridgeEvents = true; this.EventBus.HandleCardPlayed(player, card.Suit, card.Rank); } break; case TableManagerProtocolState.WaitForDisconnect: this.state = TableManagerProtocolState.Finished; this.EventBus.HandleTournamentStopped(); break; } } catch (Exception ex) { Log.Trace(0, "Error while processing message '{0}' in state {1}: {2}", message, state, ex.ToString()); throw; } } else { // unexpected message } }
public void DamageTile(Board2 board, int x, int y) { board.tileHealth[x, y]--; }
public HostBoardResult(TableManagerHost h, Board2 board, SeatCollection <string> newParticipants, BridgeEventBus bus) : base("HostBoardResult", board, newParticipants, bus, null) { this.host = h; }
public void Board_SerializeTest() { Board2 board = new Board2(@"South, All S T87432 H 53 D 72 C KT6 S QJ965 S AK H JT96 H AQ8 D 9 D KJ865 C 973 C AQ4 S H K742 D AQT43 C J852 "); var newResult = new BoardResult("owner1", board, new Participant("N", "E", "S", "W")); newResult.Auction = new Auction(newResult); newResult.Auction.Record(Bid.C("3NT")); newResult.Auction.Record(Bid.C("p")); newResult.Auction.Record(Bid.C("p")); newResult.Auction.Record(Bid.C("p")); newResult.Play = new PlaySequence(newResult.Contract, 13); newResult.Play.Record(Suits.Clubs, Ranks.Seven); newResult.Play.Record(Suits.Clubs, Ranks.Eight); newResult.Play.Record(Suits.Clubs, Ranks.Queen); newResult.Play.Record(Suits.Clubs, Ranks.Ace); newResult.Play.Record(Suits.Diamonds, Ranks.Ace); newResult.Play.Record(Suits.Diamonds, Ranks.Seven); newResult.Play.Record(Suits.Diamonds, Ranks.Two); newResult.Play.Record(Suits.Diamonds, Ranks.Four); newResult.Play.Record(Suits.Diamonds, Ranks.King); newResult.Play.Record(Suits.Diamonds, Ranks.Queen); newResult.Play.Record(Suits.Diamonds, Ranks.Three); newResult.Play.Record(Suits.Diamonds, Ranks.Five); board.Results.Add(newResult); var newResult2 = new BoardResult("owner2", board, new Participant("N2", "E2", "S2", "W2")); board.Results.Add(newResult2); var serializer = new DataContractSerializer(board.GetType()); string serializedBoard = ""; using (var sw = new StringWriter()) { using (var xw = new XmlTextWriter(sw)) { serializer.WriteObject(xw, board); } serializedBoard = sw.ToString(); } Debug.WriteLine(serializedBoard); Assert.IsNotNull(serializedBoard); Board2 copy = null; using (var sr = new StringReader(serializedBoard)) { using (var xr = new XmlTextReader(sr)) { copy = (Board2)serializer.ReadObject(xr); } } Assert.AreEqual <Board2>(board, copy, "board"); var serializer2 = new DataContractSerializer(newResult.GetType()); string serializedResult = ""; using (var sw = new StringWriter()) { using (var xw = new XmlTextWriter(sw)) { serializer2.WriteObject(xw, newResult); } serializedResult = sw.ToString(); } BoardResult resultCopy = null; using (var sr = new StringReader(serializedResult)) { using (var xr = new XmlTextReader(sr)) { resultCopy = (BoardResult)serializer2.ReadObject(xr); } } resultCopy.Board = board; Assert.AreEqual <BoardResult>(newResult, resultCopy); }