private async void ProcessBoardClick(RectangleF bounds, bool enemy, MouseEventArgs e) { int x = (int)((e.X - bounds.X) / boardCellSize); int y = (int)((e.Y - bounds.Y) / boardCellSize); effects.ForEach(i => i.BoardClick(bounds, boardCellSize, x, y)); CoordInfo coords; if (enemy) { coords = new CoordInfo() { PositionX = x, PositionY = y, Data = shotTypes[selectedShotType], CommandType = "shot" }; } else { coords = new CoordInfo() { PositionX = x, PositionY = y, Data = "testShot", CommandType = "mine" }; } await APIAccessorSingleton.Instance.PostObject <CoordInfo, CoordInfo>(string.Format("BattleSweeper/Game/{0}/ExecuteCommand", gameKey), coords); gameUpdateTimer_Tick(null, null); // TODO: Quick dirty hack, update board properly }
public static EvolutionInfo GetEvolutionInfo(string parameters, string result) { CoordInfo Seq = GetSequence(parameters, result); MathFunction[] Operators = new MathFunction[] { new Plus(), new Subtract(), new Multiply(), new Divide(), new PowerOf(), new Root(), new Exponent(), new NaturalLog(), new Log(), new Modulos(), new Floor(), new Ceil(), new Round(), new Sin(), new Cos(), new Tan(), new ASin(), new ACos(), new ATan(), new Parentheses(), new Absolute(), //new AND(), //new NAND(), //new OR(), //new NOR(), //new XOR(), //new XNOR(), //new NOT() }; return(new EvolutionInfo( Seq, // Sequence 40, // MaxSize 5, // MaxChange 30000, // CandidatesPerGen 102, // NumberRangeMax 0, // NumberRangeMin 1, // SpeciesAmount 100, // MaxStuckGens 0.8, // EvolvedCandidatesPerGen 0, // RandomCandidatesPerGen 0.2, // SmartCandidatesPerGen Operators // Operatres that can be used in an equation )); }
public void SetCustomBoardCoordinateKey(string coordToChange, string newAlgebraicKey) { CoordInfo coordInfo = GetCoordInfo(coordToChange); if (coordInfo != null) { coordInfo.algebraicKey = newAlgebraicKey; coordInfo.boardChunk.name = newAlgebraicKey; } }
public ActionResult ExecuteCommand(string key, CoordInfo info) { Game game = games.Find(game => game.Key == key); var gameNullHandler = new GameNullHandler(); var registeredPlayerHandler = new RegisteredPlayerHandler(); var finalHandler = new FinalHandler(); registeredPlayerHandler.SetNext(gameNullHandler).SetNext(finalHandler); if (!Request.Headers.ContainsKey("PlayerIdentifier")) { return(StatusCode(403)); } if (!game.HasPlayerWithIdentifier(Request.Headers["PlayerIdentifier"])) { return(StatusCode(403)); } string text = ""; if (registeredPlayerHandler.Handle(game, text) == null) { return(StatusCode(403)); } Command cmd = null; switch (info.CommandType) { case "mine": cmd = new MineCommand(info, Request.Headers["PlayerIdentifier"]); break; case "shot": cmd = new ShotCommand(info, Request.Headers["PlayerIdentifier"]); break; case "endTurn": cmd = new EndTurnCommand(info, Request.Headers["PlayerIdentifier"]); break; default: return(NotFound()); } lock (games) game.AddExecuteCommand(cmd); return(StatusCode(200)); }
/// <summary> /// Used to ensure the chess piece added to the game board has been placed in a valid position. /// </summary> /// <param name="piece">Piece to check.</param> /// <returns>True if valid placement.</returns> private bool CheckValidPlacement(ChessPiece piece) { if (AssertContainsCoord(piece.GetBoardPosition()) == false) { return(false); } else if (board.GetCoordInfo(piece.GetBoardPosition()).occupier != null && board.GetCoordInfo(piece.GetBoardPosition()).occupier.IsAlive) { CoordInfo posInfo = board.GetCoordInfo(piece.GetBoardPosition()); Debug.LogErrorFormat("OCCUPIED EXCEPTION :: " + "{0} failed to instantiate because a {1} is already at it's position! Location: {3}." , piece.ToString(), posInfo.occupier.ToString(), posInfo.algebraicKey, piece.GetBoardPosition().ToString()); return(false); } return(true); }
private async void ProcessWindowClick(object sender, MouseEventArgs e) { // determine which bounds Console.WriteLine(); if (playerBoardBounds.Contains(e.Location)) { ProcessBoardClick(playerBoardBounds, false, e); } else if (enemyBoardBounds.Contains(e.Location)) { ProcessBoardClick(enemyBoardBounds, true, e); } else if (shotTypeSelectorBounds.Contains(e.Location)) { selectedShotType = (selectedShotType + 1) % shotTypes.Count; redrawButton = true; effects.ForEach(i => i.ButtonClick(shotTypeSelectorBounds)); } else if (playerMinesBounds.Contains(e.Location)) { effects.ForEach(i => i.ButtonClick(playerMinesBounds)); try { await APIAccessorSingleton.Instance.PostObject <object, object>(string.Format("BattleSweeper/Game/{0}/UndoLastCommand", gameKey), default); } catch (APIAccessException) { } } else if (playerAmmoBounds.Contains(e.Location)) { effects.ForEach(i => i.ButtonClick(playerAmmoBounds)); CoordInfo coords = new CoordInfo() { PositionX = 0, PositionY = 0, Data = "switchingTurns", CommandType = "endTurn" }; await APIAccessorSingleton.Instance.PostObject <CoordInfo, CoordInfo>(string.Format("BattleSweeper/Game/{0}/ExecuteCommand", gameKey), coords); } else if (enemyAmmoBounds.Contains(e.Location)) { string format = "txt"; //string format = "xml"; //string format = "json"; string output = await APIAccessorSingleton.Instance.GetLogOutput(gameKey, format); SaveFile(output, format); } }
private void CreateStartPot() { Ball ball = (RaycastInfo.detectedGameElement as Ball); if (ball != null) { ball.gameObject.SetActive(false); CoordInfo coordInfo = ball.coordInfo; PotManager.Instance.SetPotState(PotManager.Instance.FindPotByCoords(coordInfo), PotState.Free); BallsManager.Instance.ballsLeft.Remove(ball); } /*if (coordInfo != null) * { * Destroy(coordInfo); * }*/ PotManager.Instance.OnUpdateScore(); StateMachineManager.Instance.stateMachine.Fire(MachineTrigger.BallClicked); }
void Update() { UpdateHoveredObj(); if (gameFinished) { return; } if (Input.GetMouseButtonDown(0)) { if (hoveredObj != null) { CoordInfo selectedCoord = chessGame.board.GetCoordInfo(GetHoveredBoardCoord()); if (hasSelection && lastSelectedOccupierAvailableMoves.Contains(GetHoveredBoardCoord())) { if (chessGame.MovePiece(lastSelectedOccupier, GetHoveredBoardCoord())) { GameManager.Instance.OnTurnComplete(); } DeSelect(); return; } if (selectedCoord.occupier != null && chessGame.IsMoversTurn(selectedCoord.occupier)) { UIManager.Instance.OnDisplayPromotionOptions(false); UIManager.Instance.OnDisplayDefectionOptions(false); hasSelection = true; lastSelectedOccupier = chessGame.board.GetCoordInfo(GetHoveredBoardCoord()).occupier; CalculateLastOccupierAvailableMoves(); return; } } } else if (Input.GetMouseButtonDown(1)) { if (hasSelection) { DeSelect(); } } }
public ActionResult SaveMessage(Message message) { if (message.Content[0] != '/') { if (message.Author.Chat == null) { message.Author.Chat = chat; } message.Author.Send(message); } else { try { Interpreter interpreter = new Interpreter(); Game game = games.Where(game => game.Player1.Name == message.Author.Name || game.Player2.Name == message.Author.Name).First(); interpreter.ParseMessage(message, game); string[] messageParts = message.Content.Split(' '); int x = int.Parse(messageParts[2]); int y = int.Parse(messageParts[3]); ChangePoint changePoint = new ChangePointLeaf(x, y); CoordInfo info = new CoordInfo(); info.CommandType = "fakeCommand"; info.PositionX = x; info.PositionY = y; FakeCommand fakeCommand = new FakeCommand(info, changePoint); game.State.HistoryObserver.Add(fakeCommand); } catch { return(BadRequest("Player hasnt started any game")); } } return(StatusCode(200)); }
public ShotCommand(CoordInfo info, string playerId) : base(info, playerId) { ShotAbstractFactory shotFactory; switch (Info.Data[0]) { case 'C': shotFactory = new CustomShotFactory(); break; case 'S': shotFactory = new SquareShotFactory(); break; default: return; } shot = shotFactory.CreateShot(Info.Data.Substring(1)); }
public MineCommand(CoordInfo info, string playerId) : base(info, playerId) { }
public EndTurnCommand(CoordInfo info, string playerId) : base(info, playerId) { }
/// <summary> /// 起爆函数 /// </summary> /// <param name="Coordinfo"></param> void burst0(int NOTBLANKNUM_CONST, CoordInfo Coordinfo) { leftdrops--; //剩余药水数减1 int row, col; //暂存横纵坐标 int drops; //?? int num; //暂存的接收水滴数 int n; //数组下标 int StartBurst; //在当下能对该坐标起作用的水滴 int i = 0; row = Coordinfo.row; //获取坐标 col = Coordinfo.col; //获取坐标 n = 6 * row + col; //将横纵坐标转换为一维数组下标 if (row < 0 || row > 5 || col < 0 || col > 5) { //坐标无效 return; } coordinfo[n].shot = Coordinfo.shot = true; //当前接收到了水滴 num = ++coordinfo[n].dropnum; //接收的水滴数加1 coordinfo[n].dropinfo[num - 1].SN++; //接收的水滴次序加1 coordinfo[n].dropinfo[num - 1].FromDirection = DIRECTION._none; //方向不是来自四周 if (A[row, col] == 0) {//该处空白,此时不必考虑水滴传播问题 coordinfo[n].shot = Coordinfo.shot = false; Coordinfo.value++; drops = coordinfo[n].value = A[row, col] = Coordinfo.value; // Picture_Refresh(row, col, drops); Clicking = true; return; } if (A[row, col] < 4) { Coordinfo.value++; drops = coordinfo[n].value = A[row, col] = Coordinfo.value; coordinfo[n].shot = Coordinfo.shot = false; coordinfo[n].dropinfo[num - 1].SN = 0;//水滴次序归零,防止之后误判 // Picture_Refresh(row, col, drops); Clicking = true; return; } /////////////////////第一轮轰炸//////////////////////////// if (A[row, col] == 4) { drops = coordinfo[n].value = A[row, col] = Coordinfo.value = 0; coordinfo[n].shot = Coordinfo.shot = false; coordinfo[n].dropinfo[num - 1].SN = 0; //水滴次序归零,防止之后误判 ProgressCount++; //水滴飞溅进展加1 // picturebox[row, col].Image = Resource1.Boomb; // picturebox[row, col].Refresh(); // Thread.Sleep(250); // Picture_Refresh(row, col, drops); splash(row, col, ProgressCount);//调用水滴飞溅函数 burstnum++; if (burstnum == 3) { leftdrops++; burstnum = 0; } Notblanknum--; } while (true) { /////////////////////////第二轮轰炸//////////////////////// for (i = 0; i < 36; i++) { if (coordinfo[i].shot) { for (StartBurst = 0; StartBurst < coordinfo[i].dropnum; StartBurst++) {//找出本轮轰炸下应该起作用的起始水滴 if (coordinfo[i].dropinfo[StartBurst].SN == ProgressCount) { break; } } for (int j = StartBurst; j < coordinfo[i].dropnum; j++) { if (coordinfo[i].dropinfo[j].SN == ProgressCount) { burst(row, col, NOTBLANKNUM_CONST, coordinfo[i], j); lastshot = true; coordinfo[i].dropinfo[j].SN = 0; if (Notblanknum == 0) { // cout<<"所有水球已被干掉!"<<endl; for (int i1 = 0; i1 < 36; i1++) { notblank[i1].value = 0; } return; } } } } } ProgressCount++; if (!lastshot) { burstnum = 0; break; } lastshot = false; } Clicking = true; return; }
public bool burst(int x, int y, int NOTBLANKNUM_CONST, CoordInfo Coordinfo, int Place) { int row, col; int n; int num; int drops; row = Coordinfo.row; col = Coordinfo.col; n = 6 * row + col; if (row < 0 || row > 5 || col < 0 || col > 5) { return(false); } if (A[row, col] == 0) { if (coordinfo[n].dropnum <= ProgressCount) { coordinfo[n].shot = Coordinfo.shot = false; } switch (Coordinfo.dropinfo[Place].FromDirection) { case DIRECTION._left: { if (coord_valid(row, col + 1)) { num = ++coordinfo[n + 1].dropnum; coordinfo[n + 1].dropinfo[num - 1].SN = ProgressCount + 1; coordinfo[n + 1].dropinfo[num - 1].FromDirection = DIRECTION._left; //方向来自左边 coordinfo[n + 1].shot = true; //当前接收到了水滴 } break; } case DIRECTION._right: { if (coord_valid(row, col - 1)) { num = ++coordinfo[n - 1].dropnum; coordinfo[n - 1].dropinfo[num - 1].SN = ProgressCount + 1; coordinfo[n - 1].dropinfo[num - 1].FromDirection = DIRECTION._right; //方向来自右边 coordinfo[n - 1].shot = true; //当前接收到了水滴 } break; } case DIRECTION._up: { if (coord_valid(row + 1, col)) { num = ++coordinfo[n + 6].dropnum; coordinfo[n + 6].dropinfo[num - 1].SN = ProgressCount + 1; coordinfo[n + 6].dropinfo[num - 1].FromDirection = DIRECTION._up; //方向来自上边 coordinfo[n + 6].shot = true; //当前接收到了水滴 } break; } case DIRECTION._down: { if (coord_valid(row - 1, col)) { num = ++coordinfo[n - 6].dropnum; coordinfo[n - 6].dropinfo[num - 1].SN = ProgressCount + 1; coordinfo[n - 6].dropinfo[num - 1].FromDirection = DIRECTION._down; //方向来自下边 coordinfo[n - 6].shot = true; //当前接收到了水滴 } break; } default: { //此情况为起爆点在第一轮过程中遭遇的情况 break; } } return(false); } if (A[row, col] < 4) { drops = coordinfo[n].value = A[row, col] = ++Coordinfo.value; for (int i = 0; i < NOTBLANKNUM_CONST; i++) { if ((notblank[i].row == row) && (notblank[i].col == col) && ((x != row) || (y != col))) { notblank[i].value = Coordinfo.value; } } if (coordinfo[n].dropnum <= ProgressCount) { coordinfo[n].shot = Coordinfo.shot = false; } // Picture_Refresh(row, col, drops); return(false); } if (A[row, col] == 4) { burstnum++; if (burstnum == 3) { leftdrops++; burstnum = 0; } drops = coordinfo[n].value = A[row, col] = Coordinfo.value = 0; for (int i = 0; i < NOTBLANKNUM_CONST; i++) { if ((notblank[i].row == row) && (notblank[i].col == col) && ((x != row) || (y != col))) { notblank[i].value = 0; Notblanknum--; } } if (coordinfo[n].dropnum <= ProgressCount) { coordinfo[n].shot = Coordinfo.shot = false; } // Thread.Sleep(250); // picturebox[row, col].Image = Resource1.Boomb; // picturebox[row, col].Refresh(); // Picture_Refresh(row, col, drops); splash(row, col, ProgressCount + 1);//调用水滴飞溅函数 return(true); } return(false); }
public FakeCommand(CoordInfo info, ChangePoint changePoint) : base(info, "") { this.Undone = true; Point = changePoint; }
public Command(CoordInfo info, string playerId) { Info = info; PlayerId = playerId; Undone = false; }