private void updateGameState(dynamic toUpdate, SingleGame game) { toUpdate.updateGameState( game.ActualGameState.ZippedState, game.SecondsLeft(), game.HasStarted); }
/// <summary> /// Clears the game gird /// </summary> internal void Clear() { LiveGame = new SingleGame { Grid = new Dictionary <string, Card>() }; LiveGameGrid?.Children.Clear(); }
public ActionResult NewGame(Models.NewGameModel newGame) { if (ModelState.IsValid) { string gameName = newGame.GameName; var newSingleGame = new SingleGame() { TourTime = newGame.TourTime, IsHidden = newGame.IsHidden }; if (Games.ActualGames.TryAdd(gameName, newSingleGame)) { Games.ShudeleGameRemoval( gameName, newSingleGame.UpdateTime, 60 * 60, "Timeout: not enough players joined within an hour."); return(RedirectToAction("Game", new Models.JoinGameModel() { GameName = newGame.GameName, Player = true })); } else { ModelState.AddModelError("GameName", "Game with that name already exists"); return(View()); } } else { return(View()); } }
internal GameForm(int i_Width, int i_Height, int i_TypeOfGame, string i_FirstPlayerName, string i_SecondPlayerName) { r_FlipTimer = new Timer() { Interval = 10 }; r_FlipTimer.Tick += flipTimer_Tick; r_ComputerTimer = new Timer() { Interval = 1000 }; r_ComputerTimer.Tick += computerTimer_Tick; m_FirstChosen = string.Empty; m_SecondChosen = string.Empty; Text = k_WindowName; r_PlayersNames[0] = i_FirstPlayerName; r_PlayersNames[1] = i_SecondPlayerName; m_CurrentGame = new SingleGame(i_Width, i_Height, i_TypeOfGame, i_FirstPlayerName, i_SecondPlayerName); r_TypeOfGame = i_TypeOfGame; AutoSize = true; r_Height = i_Height; r_Width = i_Width; r_ButtonMap = new Dictionary <string, GameButton>(i_Height * i_Width); r_PicturesMap = new PictureMap(i_Height * i_Width / 2); r_CurrentPlayerLabel = new Label(); r_PlayerLabel[0] = new Label(); r_PlayerLabel[1] = new Label(); r_EndOfGameForm = new EndOfGameForm(); m_CurrentGame.EndGame += endTheGame; m_CurrentGame.GoodMatch += updateLabel_GoodMatch; m_CurrentGame.WrongChoice += flip_WrongChoice; m_CurrentGame.AIChoice += buttonClick_AIChoice; initializeBoardComponent(); this.Shown += gameForm_Shown; }
private string PlayerName(SingleGame game) { string add1 = ""; string add2 = ""; if (game != null) { if (IsPlayer(game, false)) { add1 = "♚ "; add2 = " ♚"; } if (IsPlayer(game, true)) { add1 = "♔ "; add2 = " ♔"; } } string name = "Guest"; string proposedName = Context.RequestCookies.ContainsKey("user_name") ? Context.RequestCookies["user_name"].Value : null; if (proposedName != null && proposedName.Length > 0 && proposedName.Length < 15) { name = proposedName; } return (add1 + name + add2); }
private bool CheckStudentDomination(SingleGame Answer) { if (Answer.A.Count == A.Rows.Count) { if (Answer.A[0].Count == A.Columns.Count) { for (int i = 0; i < Answer.A.Count; i++) { for (int j = 0; j < Answer.A[0].Count; j++) { if ((Answer.A[i][j] != Convert.ToDouble(A[j, i].Value)) || (Answer.B[i][j] != Convert.ToDouble(B[j, i].Value))) { return(false); } } } } else { return(false); } } else { return(false); } return(true); }
private void OpenGrids(SingleGame G) { UI.Grid Ga = ShowGrid(A, G.A, G); UI.Grid Gb = ShowGrid(B, G.B, G); A.Left = 10; B.Left = A.Right + 50; panel1.Width = B.Right + 10; this.Width = panel1.Right + 20; A.Top = 50; B.Top = A.Top; panel1.Height = A.Bottom + 80; this.Height = panel1.Bottom + 20; label1.Text = "Игрок " + (G.pl1 + 1).ToString(); label1.Top = 10; label1.Left = A.Left + (A.Width - label1.Width) / 2; label2.Text = "Игрок " + (G.pl2 + 1).ToString(); label2.Top = label1.Top; label2.Left = B.Left + (B.Width - label2.Width) / 2; x.Text = A.Rows[0].HeaderCell.Value.ToString().Substring(0, 1) + " = ("; for (int i = 0; i < G.x.Count; i++) { x.Text += G.x[i].ToString("0.00"); if (i != G.x.Count - 1) { x.Text += " "; } else { x.Text += ")"; } } x.Top = A.Bottom + 10; x.Left = A.Left + (A.Width - x.Width) / 2; y.Text = A.Columns[0].HeaderCell.Value.ToString().Substring(0, 1) + " = ("; for (int i = 0; i < G.y.Count; i++) { y.Text += G.y[i].ToString("0.00"); if (i != G.y.Count - 1) { y.Text += " "; } else { y.Text += ")"; } } y.Top = x.Top; y.Left = B.Left + (B.Width - y.Width) / 2; }
private UI.Grid ShowGrid(DataGridView DG, List <List <double> > M, SingleGame SG) { int n = SG.A.Count, m = SG.A[0].Count; UI.StrategiesGrid G = new UI.StrategiesGrid(DG, n, m); G.InitializeHeaders("Выигрыши", SG.FirstPlayer, SG.SecondPlayer, Database.G.S); DG.ReadOnly = true; G.InitializeGrid(M); return(G); }
internal bool RunGame() { bool endGame = false; int currentPlayer = new Random().Next(0, k_NumberOfPlayers); SingleGame game = new SingleGame(r_GameBoard, r_GamePlayers, r_PlayWithComputer, r_ComputerPlayer); bool anotherGame; bool qFlag = false; bool isGoodCardMatch = false; while (!endGame) { Console.Clear(); printBoard(r_GameBoard); string firstCard, secondCard; bool computerTurn = r_PlayWithComputer && (currentPlayer == k_PlayerOneIndex); if (computerTurn) { computerChoice(out firstCard, out secondCard); } else { playerChoice(currentPlayer, out firstCard, out secondCard); } if (firstCard.Equals(k_Quit) || secondCard.Equals(k_Quit)) { qFlag = true; break; } endGame = game.RunTurnPlayer(currentPlayer, firstCard, secondCard, ref isGoodCardMatch); if (isGoodCardMatch) { goodMatch(r_GamePlayers[currentPlayer].GetPlayerNumber()); } else { badMatch(); } currentPlayer = 1 - currentPlayer; } if (qFlag) { anotherGame = false; } else { game.GetWinner(out int winner, out int winnerScore); announceWinner(winner, winnerScore, out anotherGame); } return(anotherGame); }
private void FinishBTN_Click(object sender, EventArgs e) { switch (CGStudentProgress.CurrentSection) { case 2: if (CheckStudentsStrategies()) { SkipBTN_Click(this, new EventArgs()); } break; case 3: { SingleGame D = G.SingleGames[0].Dominate(); if (CheckStudentDomination(D)) { SkipBTN_Click(this, new EventArgs()); } else { CGStudentProgress.GenerateError("Должны получиться матрицы размерностью " + D.A.Count + "x" + D.A[0].Count, null); } } break; case 4: if (CheckStudentGameSolution()) //graphical 2x2 { SkipBTN_Click(this, new EventArgs()); } break; case 5: if (CheckDivisionAndSufficiency(Coalition, YesRB_CG.Checked, YesRB_RD.Checked)) { SkipBTN_Click(this, new EventArgs()); } break; case 6: { parent.UpdateFirstGameState(Coalition, true); this.Close(); } break; default: throw new NotImplementedException(); } this.Location = new Point((Screen.PrimaryScreen.Bounds.Width - this.Width) / 2, (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2); }
public async Task JoinRoom(string roomName, bool player) { if (roomName != null) { await Groups.Add(Context.ConnectionId, roomName); usersInRooms.TryAdd(Context.ConnectionId, roomName); SingleGame game = null; Games.ActualGames.TryGetValue(roomName, out game); if (player && game != null) { lock (game) { Player playerData = new Player() { UserName = Context.User.Identity.Name, ConnectionID = Context.ConnectionId }; if (game.WhitePlayer == null) { game.WhitePlayer = playerData; } else if (game.BlackPlayer == null) { game.BlackPlayer = playerData; } else { player = false; } } } AddToChat( roomName, PlayerName(game) + (player ? " joined the game" : " joined spectators"), ""); if (player && game != null && game.HasBothPlayers) { updateGameState(Clients.All, game); } else { updateGameState(Clients.Caller, game); } } }
private void CreateArrays(int pl1, int pl2) { SingleGame SG = G.FindGame(this, pl1, pl2); Ga = new UI.StrategiesGrid(A, SG.A.Count, SG.A[0].Count); Ga.LimitedSize = true; Ga.InitializeHeaders("", SG.FirstPlayer, SG.SecondPlayer, Database.G.S); Ga.InitializeGrid(SG.A); Gb = new UI.StrategiesGrid(B, SG.A.Count, SG.A[0].Count); Gb.LimitedSize = true; Gb.InitializeHeaders("", SG.FirstPlayer, SG.SecondPlayer, Database.G.S); Gb.InitializeGrid(SG.B); }
private bool IsPlayer(SingleGame game, bool white) { Player neededPlayer = white ? game.WhitePlayer : game.BlackPlayer; if (neededPlayer == null) { return(false); } else { return (neededPlayer.ConnectionID == Context.ConnectionId); } }
internal void ResetForm() { m_CurrentGame = new SingleGame(r_Width, r_Height, r_TypeOfGame, r_PlayersNames); foreach (string position in r_ButtonMap.Keys) { resetButton(position); } setFormattedPlayerLabel(0); setFormattedPlayerLabel(1); setCurrentPlayerLabel(m_CurrentGame.CurrentPlayer); m_CurrentGame.GoodMatch += updateLabel_GoodMatch; m_CurrentGame.WrongChoice += flip_WrongChoice; m_CurrentGame.EndGame += endTheGame; m_CurrentGame.AIChoice += buttonClick_AIChoice; startComputerTurn(); }
public void SendMessage(string gameName, string text) { if (text != null && text.Length > 0 && text.Length < 300) { SingleGame game = null; if (gameName != null) { Games.ActualGames.TryGetValue(gameName, out game); } AddToChat( gameName, PlayerName(game) + ":", text); } }
/// <summary> /// Open single incooperative bimatrix game /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void UI_OpenGameForm(object sender, DataGridViewCellEventArgs e) { int i = e.RowIndex, j = e.ColumnIndex; if (i != j) { if (i > j) { i = e.ColumnIndex; j = e.RowIndex; } SingleGame G = Database.G.FindGame(sender, i, j); ViewSingleGameForm F = new ViewSingleGameForm(G); F.StartPosition = FormStartPosition.Manual; MultiFormProcessor.FormOpened(); F.Location = new Point(10, 10); F.Show(); CGStudentProgress.FormsOpened.Add(F); } }
public ActionResult Game(Models.JoinGameModel joinGame) { if (ModelState.IsValid) { SingleGame game = null; if (Games.ActualGames.TryGetValue(joinGame.GameName, out game)) { return(View(new Models.GameModel() { PiecesStates = game.ActualGameState.ZippedState, GameName = joinGame.GameName, WantsToBePlayer = joinGame.Player })); } else { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Index", "Home")); } }
public ViewSingleGameForm(SingleGame G) { InitializeComponent(); OpenGrids(G); }
/// <summary> /// Update progressbar and label when step of generation is complete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void StepComplete(object sender, ProgressChangedEventArgs e) { if (progressBar1.Value < progressBar1.Maximum) { int half = progressBar1.Maximum / 2, BimatrixGamesNumber = Database.G.N * (Database.G.N - 1) / 2; //if (progressBar1.Value != progressBar1.Maximum) progressBar1.Value = progressBar1.Value + e.ProgressPercentage; //Reset if (e.ProgressPercentage < 0) { GenerationIteration++; for (int i = 0; i < D.Rows.Count; i++) { for (int j = 0; j < D.Columns.Count; j++) { D[j, i].Value = null; } } } //Generation if (progressBar1.Value < half) { int current = progressBar1.Value / e.ProgressPercentage + 1; label1.Text = "Генерирование биматричных игр "; if (GenerationIteration > 1) { label1.Text += "[#" + GenerationIteration + "] "; } label1.Text += "(" + current + "/" + BimatrixGamesNumber + ")"; if (progressBar1.Value == 0) { label1.Left = progressBar1.Left + (progressBar1.Width - label1.Width) / 2; } if (Database.G.SingleGames.Count > 0) { SingleGame G = Database.G.SingleGames.Last(); D[G.pl2, G.pl1].Value = G.Ha.ToString("0.00"); D[G.pl1, G.pl2].Value = G.Hb.ToString("0.00"); } } //Stability check else if (progressBar1.Value < progressBar1.Maximum) { label1.Text = "Проверка устойчивости "; if (GenerationIteration > 1) { label1.Text += "[#" + GenerationIteration + "] "; } int current = (progressBar1.Value - half) / e.ProgressPercentage + 1; label1.Text += "(" + current + "/" + Database.G.CoalitionsCount + ")"; label1.Left = progressBar1.Left + (progressBar1.Width - label1.Width) / 2; } else { SingleGame G = Database.G.SingleGames.Last(); D[G.pl2, G.pl1].Value = G.Ha.ToString("0.00"); D[G.pl1, G.pl2].Value = G.Hb.ToString("0.00"); label1.Text = "Сохранение конфигурации"; label1.Left = progressBar1.Left + (progressBar1.Width - label1.Width) / 2; } } }
private void ThirdInterfaceSetup_GraphicalSolution(bool skipped) { Task2Panel.Hide(); if (skipped) { List <int> Drows = new List <int>(); List <int> Dcolumns = new List <int>(); List <string> Cheaders = new List <string>(); List <string> Rheaders = new List <string>(); SingleGame D = G.SingleGames[0].Dominate(Drows, Dcolumns); for (int i = 0; i < Drows.Count; i++) { Rheaders.Add(A.Rows[Drows[i]].HeaderCell.Value.ToString()); } for (int i = 0; i < Dcolumns.Count; i++) { Cheaders.Add(A.Columns[Dcolumns[i]].HeaderCell.Value.ToString()); } Ga = new UI.StrategiesGrid(A, D.A.Count, D.A[0].Count); Gb = new UI.StrategiesGrid(B, D.A.Count, D.A[0].Count); Ga.LimitedSize = true; Gb.LimitedSize = true; Ga.InitializeHeaders("", G.SingleGames[0].FirstPlayer, G.SingleGames[0].SecondPlayer, Database.G.S); Gb.InitializeHeaders("", G.SingleGames[0].FirstPlayer, G.SingleGames[0].SecondPlayer, Database.G.S); Ga.InitializeGrid(D.A); Gb.InitializeGrid(D.B); for (int i = 0; i < A.Rows.Count; i++) { A.Rows[i].HeaderCell.Value = Rheaders[i]; B.Rows[i].HeaderCell.Value = Rheaders[i]; } for (int j = 0; j < A.ColumnCount; j++) { A.Columns[j].HeaderCell.Value = Cheaders[j]; B.Columns[j].HeaderCell.Value = Cheaders[j]; } } if ((A.Rows.Count == 2) && (A.Columns.Count == 2)) { Graphical2x2SolutionPanel.Show(); UI.ControlsAligner gpanel = new UI.ControlsAligner(MatrixesPanel); gpanel.AddElement(A); gpanel.AddElement(B, false); gpanel.Align(); UI.ControlsAligner form = new UI.ControlsAligner(this); form.AddElement(MatrixesPanel); form.AddElement(Graphical2x2SolutionPanel); form.AddElement(SkipBTN, true, "Left"); form.AddElement(FinishBTN, false, "Right"); form.Align(); } else { CGStudentProgress.NewSection(); FourthInterfaceSetup_PayoffDistributionAndSufficiency(); } }
void ExecuteHookWithNameAndData(string name, SingleGame.Conditional data) { hooks.Add(name); if (name == "draw") { StartCoroutine(draw()); return; } if (name == "highlight") { Debug.Log("highlight"); Debug.Log(data); SingleGame.GameManager.endHook(); hooks.Remove("highlight"); return; } if (name == "log") { Debug.Log("hooklog"); Debug.Log(data["text"]); hooks.Remove("log"); SingleGame.GameManager.endHook(); return; } if (name == "discard") { Debug.Log("discarded"); refreshBodies(); hooks.Remove(name); SingleGame.GameManager.endHook(); return; } if (name == "test") { Debug.Log("testlog"); Debug.Log(data["active.abilities"]); Debug.Log(data["active._cardName"]); Debug.Log(((IList)data["_sel"]).Count); // Debug.Log(data["_ability"]); //Debug.Log(((SingleGame.Conditional)data["_target.TARGETED"]).hasTag("DISTANCE_TICKER")); //Debug.Log(((IList)data["_used"]).Count); // Debug.Log(data["_Owner.BODY"]); //Debug.Log(data.hasTag(player1["activeTag"] as string)); //IList dl=data["_used"] as IList; // Debug.Log(dl.Count); hooks.Remove("test"); SingleGame.GameManager.endHook(); return; } if (name == "act") { SingleGame.Conditional cnd = data["TARGETED"] as SingleGame.Conditional; string st2 = data["TARGETED._cardName"] as string; if (st2 == null) { st2 = data["TARGETED.slot"] as string; } if (cnd.hasTag("DISTANCE_TICKER")) { st2 = "MOVE"; } Debug.Log(string.Format("Enemy acted randomly: {0} {1} {2}", data["SELECTED._cardName"], st2, data["AIMED._cardName"])); hooks.Remove(name); SingleGame.GameManager.endHook(); return; } if (name == "id") { Debug.Log("idlog"); data["playerID"] = SingleGame.getRandString(12); Debug.Log(data["playerID"]); hooks.Remove(name); SingleGame.GameManager.endHook(); return; } if (name == "shuffle") { Debug.Log("shuffle"); IList dl = player1["DISCARD"] as IList; Debug.Log(dl.Count); dl = player1["DECK"] as IList; Debug.Log(dl.Count); Debug.Log(player1 == data); hooks.Remove(name); SingleGame.GameManager.endHook(); // postshuf=true; return; } if (name == "transformation") { StartCoroutine(trans()); return; } Debug.Log(string.Format("Undefined Hook called: {0}", name)); hooks.Remove(name); SingleGame.GameManager.endHook(); }
/// <summary> /// /// </summary> /// <param name="game">Cannot be null</param> /// <returns></returns> private bool PlayersTurn(SingleGame game) { return(game.HasStarted && IsPlayer(game, game.ActualGameState.Tour == ChessGameState.Color.White)); }
void ExecuteHookWithNameAndData(string name,SingleGame.Conditional data ) { hooks.Add(name); if(name=="draw") { StartCoroutine(draw ()); return; } if(name=="highlight") { Debug.Log("highlight"); Debug.Log(data); SingleGame.GameManager.endHook(); hooks.Remove("highlight"); return; } if(name=="log") { Debug.Log("hooklog"); Debug.Log(data["text"]); hooks.Remove("log"); SingleGame.GameManager.endHook(); return; } if(name=="discard") { Debug.Log("discarded"); refreshBodies(); hooks.Remove(name); SingleGame.GameManager.endHook(); return; } if(name=="test") { Debug.Log("testlog"); Debug.Log(data["active.abilities"]); Debug.Log(data["active._cardName"]); Debug.Log(((IList)data["_sel"]).Count); // Debug.Log(data["_ability"]); //Debug.Log(((SingleGame.Conditional)data["_target.TARGETED"]).hasTag("DISTANCE_TICKER")); //Debug.Log(((IList)data["_used"]).Count); // Debug.Log(data["_Owner.BODY"]); //Debug.Log(data.hasTag(player1["activeTag"] as string)); //IList dl=data["_used"] as IList; // Debug.Log(dl.Count); hooks.Remove("test"); SingleGame.GameManager.endHook(); return; } if(name=="act") { SingleGame.Conditional cnd=data["TARGETED"] as SingleGame.Conditional; string st2=data["TARGETED._cardName"] as string; if(st2==null) st2=data["TARGETED.slot"] as string; if(cnd.hasTag("DISTANCE_TICKER")) st2="MOVE"; Debug.Log(string.Format("Enemy acted randomly: {0} {1} {2}",data["SELECTED._cardName"],st2,data["AIMED._cardName"])); hooks.Remove(name); SingleGame.GameManager.endHook(); return; } if(name=="id") { Debug.Log("idlog"); data["playerID"]=SingleGame.getRandString(12); Debug.Log(data["playerID"]); hooks.Remove(name); SingleGame.GameManager.endHook(); return; } if(name=="shuffle") { Debug.Log("shuffle"); IList dl=player1["DISCARD"] as IList; Debug.Log(dl.Count); dl=player1["DECK"] as IList; Debug.Log(dl.Count); Debug.Log(player1==data); hooks.Remove(name); SingleGame.GameManager.endHook(); // postshuf=true; return; } if(name=="transformation") { StartCoroutine(trans()); return; } Debug.Log(string.Format("Undefined Hook called: {0}",name)); hooks.Remove(name); SingleGame.GameManager.endHook(); }
RectTransform getAssociatedRect(SingleGame.Conditional ev) { SingleGame.Conditional src=ev["castSource"] as SingleGame.Conditional; SingleGame.Conditional em=ev["castEmitter"] as SingleGame.Conditional; foreach(CardReceptor cr in mpBody) if(cr.cardData==src) return cr.gameObject.GetComponent<RectTransform>(); foreach(CardControl cr in handCards) if(cr.cardData==src) return cr.gameObject.GetComponent<RectTransform>(); foreach(CardReceptor cr in mpBody) if(cr.cardData==em) return cr.gameObject.GetComponent<RectTransform>(); return null; }