private void checkAndAddMoves(byte i_SpaceIndex, eTeam i_CurrentTeam, eDirection i_Direction, List <Move> io_CurrentTeamMoveList) { int teamMultiplier = i_CurrentTeam == eTeam.Black ? 1 : -1; int directionMultiplier = (int)i_Direction; int stepTo; byte boardSize = (byte)m_Board.BoardSize; bool isInScopeForMove = i_Direction == eDirection.Left ? !(i_SpaceIndex % boardSize == 0) : !((i_SpaceIndex % boardSize) == (boardSize - 1)); bool checkAgainForKing = m_Board.Spaces[i_SpaceIndex].Piece.IsKing; byte timesChecked = 0; do { stepTo = (byte)(i_SpaceIndex - ((teamMultiplier * boardSize) + directionMultiplier)); if (isInScopeForMove && // piece is not next to the left border (stepTo >= 0) && // The wanted move is in boundaries stepTo < Math.Pow(boardSize, 2) && // The wanted move is in boundaries m_Board.Spaces[stepTo].SpaceState == Space.eSpaceState.Empty && // wanted space to move is empty ((i_SpaceIndex / boardSize) == (stepTo / boardSize) + teamMultiplier) // make sure destination is in the row it should be at BUG FIX ) { Move newMove = new Move(i_SpaceIndex, (byte)stepTo); io_CurrentTeamMoveList.Add(newMove); } if (checkAgainForKing) { timesChecked++; teamMultiplier *= -1; } }while (checkAgainForKing && timesChecked < 2); }
private bool checkAndAddJumpMoves(byte i_SpaceIndex, eTeam i_CurrentTeam, eDirection i_Direction, List <Move> io_CurrentTeamMoveList) { int teamMultiplier = i_CurrentTeam == eTeam.Black ? 1 : -1; int directionMultiplier = (int)i_Direction; int jumpTo; bool checkAgainForKing = m_Board.Spaces[i_SpaceIndex].Piece.IsKing, jumpMove = false; byte boardSize = (byte)m_Board.BoardSize, timesChecked = 0; do { jumpTo = i_SpaceIndex - ((2 * teamMultiplier * (byte)m_Board.BoardSize) + (2 * directionMultiplier)); if (isDestinationBeneathUpperBorder(jumpTo) && isDestinationAboveLowerBorder(jumpTo) && isDestinationWithinLeftRightBorders(i_SpaceIndex, i_Direction, boardSize) && isThereAPieceToBeJumpedOver(i_SpaceIndex, directionMultiplier, teamMultiplier, boardSize) && isThePieceIJumpOverIsOpponent(i_SpaceIndex, directionMultiplier, teamMultiplier, boardSize, i_CurrentTeam) && isDestinationEmpty(jumpTo)) { jumpMove = true; Move newMove = new Move(i_SpaceIndex, (byte)jumpTo, jumpMove); io_CurrentTeamMoveList.Add(newMove); } // if the current piece is a king, we check moves both upwards and downwards if (checkAgainForKing) { timesChecked++; teamMultiplier *= -1; } }while (checkAgainForKing && timesChecked < 2); return(jumpMove); }
public Warrior(string name, eTeam team = eTeam.Good, int health = _healthMax, int strength = 100) : base(name, team, health) { Strength = strength; }
// constructor public GameState(Board i_Board, eGameMode i_Mode) { this.m_Board = i_Board; this.m_CurrentGameMode = i_Mode; this.m_CurrentTeam = eTeam.Black; this.m_PieceCountBlack = this.m_PieceCountRed = (byte)(((byte)i_Board.BoardSize / 2) * (((byte)i_Board.BoardSize / 2) - 1)); // initialize piece count for both sides }
public eGameState CalcGameState(eTeam i_CurrentTeamMove) { eGameState gameStateResult = gameHasWinner(i_CurrentTeamMove); if (eGameState.GameIsInProgress == gameStateResult) { bool player1HasMoves = checkPlayerHasAvailableMove(eTeam.Player1); bool player2HasMoves = checkPlayerHasAvailableMove(eTeam.Player2); if (!player1HasMoves && !player2HasMoves) { gameStateResult = eGameState.Tie; } else if (!player2HasMoves) { gameStateResult = eGameState.Player1Won; } else if (!player1HasMoves) { gameStateResult = eGameState.Player2Won; } } return(gameStateResult); }
static public void SendPassThroughMessage(int x, int y, eTeam team, string msg = "0") { if (client == null || client.socket == null || client.socket.Connected == false) { return; } var bytearray = System.Text.Encoding.UTF8.GetBytes(msg); ROOM_PASS_THROUGH_REQ message = new ROOM_PASS_THROUGH_REQ { VarMessage = ByteString.CopyFrom(bytearray), }; int flag = 0; Helper.SET_X_Y_COLOR((sbyte)x, (sbyte)y, (byte)(team == eTeam.White ? 0 : 1), ref flag); message.VarMessageInt = flag; using (MemoryStream stream = new MemoryStream()) { message.WriteTo(stream); client.WritePacket((int)PROTOCOL.IdPktRoomPassThroughReq, stream.ToArray(), stream.ToArray().Length); } }
public override List <Position> GetAllSkipMoves(Position i_CurrentPosition, CheckersGameObject[,] i_GameBoard) { int toAddRow = i_GameBoard[i_CurrentPosition.Row, i_CurrentPosition.Col].Team == eTeam.Player2 ? 1 : -1; int[] colValues = { 1, -1 }; eTeam enemy = OpponentUtils.GetOpponent(this.Team); List <Position> skipPositions = new List <Position>(); for (int i = 0; i < 2; i++) { int rowsToSearchEnemy = i_CurrentPosition.Row + toAddRow; int colsToSearchEnemy = i_CurrentPosition.Col + colValues[i]; if (!isMoveInsideBoard(new Position(rowsToSearchEnemy, colsToSearchEnemy), i_GameBoard)) { continue; } if (i_GameBoard[rowsToSearchEnemy, colsToSearchEnemy].Team == enemy) { int rowsToSearchEmpty = i_CurrentPosition.Row + (toAddRow * 2); int colsToSearchEmpty = i_CurrentPosition.Col + (colValues[i] * 2); if (!isMoveInsideBoard(new Position(rowsToSearchEmpty, colsToSearchEmpty), i_GameBoard)) { continue; } if (i_GameBoard[rowsToSearchEmpty, colsToSearchEmpty].Team == eTeam.Empty) { skipPositions.Add(new Position(rowsToSearchEmpty, colsToSearchEmpty)); } } } return(skipPositions); }
/* * Player constructor for initilize the player. */ public Player(string i_Name, bool i_IsAI, eTeam i_Team) { m_Name = i_Name; m_IsAI = i_IsAI; r_Team = i_Team; List <Piece> m_Pieces = new List <Piece>(); }
// Player Constructor public Player(string i_Name, bool i_PlayerIsComputer, eTeam i_Team) { m_Name = i_Name; m_PlayerIsComputer = i_PlayerIsComputer; r_Team = i_Team; List <Piece> m_Pieces = new List <Piece>(); }
private bool checkPlayerHasAvailableMove(eTeam i_CurrentTeamMove) { List <Position> teamPositions = getCurrentPlayerGameObjects(i_CurrentTeamMove); bool hasMove = false; foreach (Position position in teamPositions) { bool hasSkipOption = r_Board[position.Row, position.Col].HasAvailableSkip(position, this.r_Board); if (hasSkipOption) { hasMove = true; break; } } if (!hasMove) { foreach (Position position in teamPositions) { List <Position> availablePositions = r_Board[position.Row, position.Col].GetAvailableMoves(position, this.r_Board); if (availablePositions.Count > 0) { hasMove = true; break; } } } return(hasMove); }
public void MakeMove(int i_SourceRow, int i_SourceCol, int i_DestinationRow, int i_DestinationCol) { Position sourcePosition = new Position(i_SourceRow, i_SourceCol); Position destinationPosition = new Position(i_DestinationRow, i_DestinationCol); string error = string.Empty; if (this.r_GameBoard.CheckMoveIsValid(sourcePosition, destinationPosition, this.m_PlayerTurn, ref error)) { bool hasAvailableSkipMove = this.r_GameBoard.MoveSoldierInBoard(sourcePosition, destinationPosition, this.m_PlayerTurn); this.m_NewGame = false; getUpdatedGameState(); if (!hasAvailableSkipMove && this.m_GameState == eGameState.GameIsInProgress && this.m_NewGame == false) { this.m_PlayerTurn = OpponentUtils.GetOpponent(this.m_PlayerTurn); if (this.r_IsPlayer2Computer && this.m_PlayerTurn == eTeam.Player2) { this.r_GameBoard.RunComputerMove(this.m_PlayerTurn); this.m_PlayerTurn = OpponentUtils.GetOpponent(this.m_PlayerTurn); getUpdatedGameState(); } } } else { if (this.ReportGameError != null) { this.ReportGameError.Invoke(error); } } }
public void ProcReceivePutStoneMessage(ROOM_PASS_THROUGH_RES res) { sbyte x = 0, y = 0; byte icolor = 0; Helper.Get_X_Y_COLOR(ref x, ref y, ref icolor, res.VarMessageInt); eTeam color = icolor == 0 ? eTeam.White : eTeam.Black; if (CheckValid(x, y) == true) //시간만료면 false { _renderer.UpdateStone(x, y, color, false); } debug++; //check turn { if (User.Color == color) { User.IsMyTurn = false; } else { _ai.aix = x; _ai.aiy = y; User.IsMyTurn = true; User.MytrunStartTime = DateTime.Now; } //순서는 반대로 흑이 했다면 다음은 백이 할차례 _renderer.UpdateTurnBackground(icolor == 0 ? eTeam.Black : eTeam.White); } }
private eGameState gameHasWinner(eTeam i_CurrentTeamMove) { eGameState gameStateResult = eGameState.GameIsInProgress; eTeam enemy = OpponentUtils.GetOpponent(i_CurrentTeamMove); int enenyCount = 0; for (int x = 0; x < this.r_Board.GetLength(1); x++) { for (int y = 0; y < this.r_Board.GetLength(1); y++) { if (this.r_Board[x, y].Team == enemy) { enenyCount++; } } } if (enenyCount == 0) { if (enemy == eTeam.Player1) { gameStateResult = eGameState.Player2Won; } else { gameStateResult = eGameState.Player1Won; } } return(gameStateResult); }
private void OnBallTouchFloor(GameEvents.BallTouchFloorEvent e) { if (_currentState == eGameState.Play) { float hitX = e.ContactPoint.x; bool isOOB = (Mathf.Abs(hitX) > LevelManager.Instance.GetOOBXForSide(eTeam.Away)); // we only use away here because it's positive eTeam awardedSide = (hitX < LevelManager.Instance.GetNetPosition().x ? eTeam.Away : eTeam.Home); if (isOOB || _ballUnderNet) { awardedSide = (awardedSide == eTeam.Home ? eTeam.Away : eTeam.Home); } bool isGameOver = UpdateScore(awardedSide); if (isGameOver) { SetState(eGameState.Over); } else { _servingTeamIndex = (int)awardedSide; SetState(eGameState.Serve); } _ballUnderNet = false; } }
public bool MoveSoldierInBoard(Position i_Source, Position i_Destination, eTeam i_CurrentTeamMove) { bool hasMultipleSkips = false; CheckersGameObject currentGameObject = this.r_Board[i_Source.Row, i_Source.Col]; CheckersGameObject desGameObject = this.r_Board[i_Destination.Row, i_Destination.Col]; this.r_Board[i_Source.Row, i_Source.Col] = desGameObject; this.r_Board[i_Destination.Row, i_Destination.Col] = currentGameObject; this.m_BoardDelegates[i_Source.Row, i_Source.Col].TriggerChange(desGameObject.ToString()); this.m_BoardDelegates[i_Destination.Row, i_Destination.Col].TriggerChange(currentGameObject.ToString()); checkAndUpdateIfHaveNewKings(); if (Math.Abs(i_Source.Row - i_Destination.Row) == 2 && Math.Abs(i_Source.Col - i_Destination.Col) == 2) { int eatenPawnRow = (i_Source.Row + i_Destination.Row) / 2; int eatenPawnCol = (i_Source.Col + i_Destination.Col) / 2; this.r_Board[eatenPawnRow, eatenPawnCol] = new EmptySlot(eTeam.Empty); this.m_BoardDelegates[eatenPawnRow, eatenPawnCol].TriggerChange(this.r_Board[eatenPawnRow, eatenPawnCol].ToString()); if (this.r_Board[i_Destination.Row, i_Destination.Col].HasAvailableSkip(new Position(i_Destination.Row, i_Destination.Col), this.r_Board)) { this.m_HasMultipleSkipsOption = new Position(i_Destination.Row, i_Destination.Col); hasMultipleSkips = true; } else { this.m_HasMultipleSkipsOption = null; } } return(hasMultipleSkips); }
public Wizard(string name, eTeam team = eTeam.Good, int health = _healthMax, int mana = 100) : base(name, team, health) { Mana = mana; }
private bool checkCurrentPlayerHasSkipOption(eTeam i_CurrentTeamMove) { bool hasSkipOption = false; for (int x = 0; x < this.r_Board.GetLength(1); x++) { for (int y = 0; y < this.r_Board.GetLength(1); y++) { if (this.r_Board[x, y].Team == i_CurrentTeamMove) { if (this.r_Board[x, y].HasAvailableSkip(new Position(x, y), this.r_Board)) { hasSkipOption = true; break; } } } if (hasSkipOption) { break; } } return(hasSkipOption); }
public Character(string name, eTeam team = eTeam.Good, int health = _healthMax) { Name = name; Team = team; Health = health; _counter++; }
public static int NumOfLegalMoves(GameState gameState, eTeam team) { if (IsCheckedState(gameState, team)) { int a = 0; } return(20); }
static eTeam NextTeam(eTeam team) { if (team == eTeam.WHITE) { return(eTeam.BLACK); } return(eTeam.WHITE); }
public void ResetGame() { this.calcScore(); this.r_GameBoard.ResetBoard(); this.m_PlayerTurn = eTeam.Player1; this.m_GameState = eGameState.GameIsInProgress; this.m_NewGame = true; }
private void InitUI(eTeam team, PlayerController pCtrl, int index) { pCtrl.Init(team); (team == eTeam.Red ? _team1ChacUI : _team2ChacUI)[index % 2].Init(pCtrl); _indexViewidBox.Add(index, pCtrl._pView.ViewID); }
public Color32 TeamColor(eTeam t) { if (t == eTeam.BLACK) { return(new Color32(0, 0, 0, 255)); } return(new Color32(255, 255, 255, 255)); }
private bool checkMoveIsMadeOnCurrentPlayerGameObject( Position i_CurrentPosition, eTeam i_CurrentTeamMove) { eTeam movedItemTeam = this.r_Board[i_CurrentPosition.Row, i_CurrentPosition.Col].Team; return(i_CurrentTeamMove == movedItemTeam); }
//---------------------------------Public functions-------------------------------- /* * InitializeGame is a method that initialize the game. */ public void InitializeGame() { m_Player1.Pieces.Clear(); m_Player2.Pieces.Clear(); initializeStartPositionOfPiecesOnBoard(); m_Winner = null; s_Turn = eTeam.Black; buildCurrentValidMovesList(); }
public static List <GameState> NextStates(GameState gameState, eTeam team) { List <GameState> L = new List <GameState>(); int c; if (team == eTeam.BLACK) { c = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (gameState.Pieces[i][j].Team == team) { c++; foreach (Pairii pair in Path(gameState.Pieces[i][j], gameState, i, j)) { int m = pair.Key; int n = pair.Value; L.Add(ChangeState(gameState, i, j, m, n)); } if (c >= 16) { return(L); } } } } } else { c = 0; for (int i = 7; i >= 0; i--) { for (int j = 0; j < 8; j++) { if (gameState.Pieces[i][j].Team == team) { c++; foreach (Pairii pair in Path(gameState.Pieces[i][j], gameState, i, j)) { int m = pair.Key; int n = pair.Value; L.Add(ChangeState(gameState, i, j, m, n)); } if (c >= 16) { return(L); } } } } } return(L); }
public void UpdateScores() { eTeam winningTeam = GetRoundWinner(); float nmeDistanceFromBullseye = GetNMEClosestToBullseye(winningTeam); GivePoints(winningTeam, nmeDistanceFromBullseye); print(winningTeam); print(team1score); print(team2score); }
public static eTeam GetOpponent(eTeam i_PlayerTeam) { if (i_PlayerTeam == eTeam.Player1) { return(eTeam.Player2); } else { return(eTeam.Player1); } }
private void SwitchFirstTeam() { if (firstTeam == eTeam.TEAM_BLUE) { firstTeam = eTeam.TEAM_RED; } else { firstTeam = eTeam.TEAM_BLUE; } }
public static bool IsCheckMated(GameState game, eTeam team) { foreach (GameState gs in AI_Script.NextStates(game, team)) { if (!IsChecked(gs, team)) { return(false); } } return(true); }
public Unit(Game game, eTeam team) : base(game) { m_Legs = new GameObject[2]; for (int i = 0; i < m_Legs.Length; i++) { m_Legs[i] = new GameObject(game); } m_Team = team; m_ModelRotation = Quaternion.Concatenate(Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), (float)Math.PI / 2), Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), (float)Math.PI)); ShootTime = 10000; m_Health = MaxHealth; m_SpawnTime = 0; m_DieTime = 0; TimeUntilPathExpire = 0; Flying = false; m_FlyingState = false; foreach (GameObject leg in m_Legs) { GameState.Get().SpawnGameObject(leg); } }
public SpawnPoint(Game game, eTeam t) : base(game) { team = t; name = "SpawnPoint"+t; }
private void GiveWinningTeamPoints( eTeam team, int points ) { switch ( team ) { case eTeam.TEAM_RED:{ team1score += points; team1currentscore += points; break; } case eTeam.TEAM_BLUE:{ team2score += points; team2currentscore += points; break; } } }
private void GivePoints( eTeam winningTeam, float enemyDistanceFromBullseye ) { int points = 0; foreach ( Rock rock in FindObjectsOfType<Rock>() ) { if ( rock.team == winningTeam ) { if ( rock.DistanceFromBullseye() < enemyDistanceFromBullseye ) { points++; } } } GiveWinningTeamPoints( winningTeam, points ); }
private float GetEnemyClosestToBullseye( eTeam winningTeam ) { float closestToBullseye = 99999.9f; foreach ( Rock rock in FindObjectsOfType<Rock>() ) { if ( rock.team != winningTeam ) { if ( rock.DistanceFromBullseye() < closestToBullseye ) { closestToBullseye = rock.DistanceFromBullseye(); } } } return closestToBullseye; }
public void SetPositionAndTeam(Vector3 iPosition, eTeam iTeam) { StartPosition = iPosition; Position = iPosition; rigidbody.position = iPosition; Team = iTeam; if (Team == eTeam.Blue) { Dwarf.transform.FindChild("head_geo").renderer.material = BlueSkin; Dwarf.transform.FindChild("body").renderer.material = BlueSkin; UnityLightLightOnly.color = new Color(0.5f, 0.5f, 0.8f, 1.0f); UnityLight.color = new Color(0.5f, 0.5f, 0.8f, 1.0f); TeamNumber = 0; } else { Dwarf.transform.FindChild("head_geo").renderer.material = RedSkin; Dwarf.transform.FindChild("body").renderer.material = RedSkin; UnityLightLightOnly.color = new Color(0.8f, 0.5f, 0.5f, 1.0f); UnityLight.color = new Color(0.8f, 0.5f, 0.5f, 1.0f); TeamNumber = 1; } UnityLightLightOnly.shadows = LightShadows.None; UnityLight.shadows = LightShadows.Soft; LightOn = false; HasFlag = false; IsDead = false; }
protected virtual void addToTeam(PlayerController pc, eTeam team) { }