//Rolls the dice and calls for each possible checker that can be moved to be highlighted IEnumerator rollDice() { rolledValues = dice.throwDice(true); yield return(new WaitForSeconds(waitForDiceRollTime)); if (currGamePhase == turnPhase.BlackTurn && againstAI) { StartCoroutine(doAIMove()); currGamePhase = turnPhase.WhiteTurn; } else { movesLeftForTurn = 2; usedRoll1 = false; usedRoll2 = false; if (rolledValues[0] == rolledValues[1]) { movesLeftForTurn = 4; } getLegalMoves(rolledValues[0], rolledValues[1]); } }
// Use this for initialization void Start() { currentPhase = turnPhase.WAITING_FOR_ROLL; currentPlayerId = 0; theDiceRoller = GameObject.FindObjectOfType <DiceRoller>(); turnText = GameObject.Find("PlayerText").GetComponent <Text>(); }
IEnumerator determinePlayerOrder() { rolledValues = dice.throwDice(false); //This will get rolled values that are not the same, so player order can be determined yield return(new WaitForSeconds(waitForDiceRollTime)); //Yields actions to allow dice to finish rolling before continuing //The first dice is for the white checkers player, so if they are the bigger number then they go first if (rolledValues[0] > rolledValues[1]) { currGamePhase = turnPhase.WhiteTurn; movesLeftForTurn = 2; usedRoll1 = false; usedRoll2 = false; getLegalMoves(rolledValues[0], rolledValues[1]); //Get legal moves will highlight each checker that the current player can move } //Else black checkers player goes first else { currGamePhase = turnPhase.BlackTurn; if (againstAI) { StartCoroutine(doAIMove()); currGamePhase = turnPhase.WhiteTurn; //After AI, give control back to white player } else { movesLeftForTurn = 2; usedRoll1 = false; usedRoll2 = false; getLegalMoves(rolledValues[0], rolledValues[1]); } } }
IEnumerator noLegalMoveCoroutine() { //display message //wait a sec //setup the new turn yield return(new WaitForSeconds(1f)); currentPhase = turnPhase.WAITING_FOR_NEWTURN; }
public void NextPhase() { switch (currentPhase) { case turnPhase.Standby: currentPhase = turnPhase.TurnTitle; BeginPhaseTitle(); break; case turnPhase.TurnTitle: currentPhase = turnPhase.EnergyGen; BeginPhaseEnergy(); break; case turnPhase.EnergyGen: currentPhase = turnPhase.Recalibrate; BeginPhaseRecalibrate(); break; case turnPhase.Recalibrate: currentPhase = turnPhase.DrawPhase; BeginPhaseDraw(); break; case turnPhase.DrawPhase: currentPhase = turnPhase.Strategy; BeginPhaseStrategy(); break; case turnPhase.Strategy: currentPhase = turnPhase.Resolution; BeginPhaseResolution(); break; case turnPhase.Resolution: currentPhase = turnPhase.Discard; BeginPhaseDiscard(); break; case turnPhase.Discard: currentPhase = turnPhase.Standby; BeginPhaseStandby(); break; } //Debug.Log(currentPhase); }
/* board[23] is last pointe * board[24-25] is whiteBar and blackBar respectively * board[26-27] is white checkers bared off and black checkers bared off */ //On scene start, set up the board private void Start() { dice.resetDicePos(); //Sets dice to rest position arrangeBoard(); //Arrange starting board configuration assignPointePos(); //Ensure each pointe knows which pointe it is //Display AI table if against AI if (againstAI) { AIMoveInformation.gameObject.SetActive(true); } //initial game configuration states currGamePhase = turnPhase.StartGame; whiteCheckerPhase = gamePhase.Regular; blackCheckerPhase = gamePhase.Regular; //Player order is determined by the first roll, where higher number goes first StartCoroutine(determinePlayerOrder()); }
public void newTurn() { //This is the start of a player's turn //we don't have a roll for them yet currentPlayerId = (currentPlayerId + 1) % numberOfPlayers; currentPhase = turnPhase.WAITING_FOR_ROLL; if (currentPlayerId == 0) { turnText.text = "Current Player: One"; } else { turnText.text = "Current Player: Two"; } this.isDoneRolling = false; this.isDoneClicking = false; this.isDoneAnimating = false; theDiceRoller.transform.GetChild(4).GetComponent <Text>().text = "?"; }
//Deal with releasing a selected checker, either moving it or resetting it private void releaseSelectedChecker() { RaycastHit[] hits; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); hits = Physics.RaycastAll(ray); bool clickedPointe = false; int newPointePos = 0; for (int i = 0; i < hits.Length; i++) { PointeManager pointeSelected = hits[i].transform.GetComponent <PointeManager>(); BaringOffManager clickedBaringOff = hits[i].transform.GetComponent <BaringOffManager>(); if (pointeSelected && pointeSelected.isClickable()) { clickedPointe = true; newPointePos = pointeSelected.getPos(); //Look at board seperately for white phase vs black if (currGamePhase == turnPhase.WhiteTurn) { //Check for hit and do actions if hit if (board[newPointePos] == -1) { blackCheckerPhase = gamePhase.Regular; Checker removedChecker = pointes[newPointePos].removeChecker(); removedChecker.setPos(25); bar.addCheckerOnBar(removedChecker); board[newPointePos] = 0; board[25]--; } if (board[24] > 0) { Checker removedChecker = bar.removeCheckerOnBar(true); removedChecker.setPos(newPointePos); pointes[newPointePos].addChecker(removedChecker); selectedCheckerOrigBoardPos = 24; board[24]--; } //Not on bar, then regular move and do actions else { Checker removedChecker = pointes[selectedCheckerOrigBoardPos].removeChecker(); removedChecker.setPos(newPointePos); pointes[newPointePos].addChecker(removedChecker); board[selectedCheckerOrigBoardPos]--; } board[newPointePos]++; } else if (currGamePhase == turnPhase.BlackTurn) { //Check for hit and do actions if hit if (board[newPointePos] == 1) { whiteCheckerPhase = gamePhase.Regular; Checker removedChecker = pointes[newPointePos].removeChecker(); removedChecker.setPos(24); bar.addCheckerOnBar(removedChecker); board[newPointePos] = 0; board[24]++; } if (board[25] < 0) { Checker removedChecker = bar.removeCheckerOnBar(false); removedChecker.setPos(newPointePos); pointes[newPointePos].addChecker(removedChecker); selectedCheckerOrigBoardPos = -1; board[25]++; } //Not on bar, then regular move and do actions else { Checker removedChecker = pointes[selectedCheckerOrigBoardPos].removeChecker(); removedChecker.setPos(newPointePos); pointes[newPointePos].addChecker(removedChecker); board[selectedCheckerOrigBoardPos]++; } board[newPointePos]--; } } else if (clickedBaringOff && clickedBaringOff.isClickable()) { clickedPointe = true; Checker removedChecker = pointes[selectedCheckerOrigBoardPos].removeChecker(); baringOff.addCheckerBaringOff(removedChecker); if (currGamePhase == turnPhase.WhiteTurn) { removedChecker.setPos(26); board[selectedCheckerOrigBoardPos]--; board[26]++; newPointePos = -1; } else { removedChecker.setPos(27); board[selectedCheckerOrigBoardPos]++; board[27]--; newPointePos = 24; } baringOff.changeHighlightBaringOff(false); } } if (clickedPointe) { removeCheckerHighlights(); movesLeftForTurn--; if (currGamePhase == turnPhase.WhiteTurn) { if (board[26] == MAXCHECKERS) { StartCoroutine(finishGame(true)); } if (whiteCanBearOff()) { whiteCheckerPhase = gamePhase.BaringOff; } } else { if (-board[27] == MAXCHECKERS) { StartCoroutine(finishGame(false)); } if (blackCanBearOff()) { blackCheckerPhase = gamePhase.BaringOff; } } if (movesLeftForTurn == 0) { //Switch turns dice.resetDicePos(); if (currGamePhase == turnPhase.WhiteTurn) { currGamePhase = turnPhase.BlackTurn; if (againstAI) { rolledValues = dice.throwDice(true); StartCoroutine(doAIMove()); currGamePhase = turnPhase.WhiteTurn; } } else { currGamePhase = turnPhase.WhiteTurn; } } else if (rolledValues[0] == rolledValues[1]) { usedRoll1 = true; getLegalMoves(-1, rolledValues[1]); } else if (Mathf.Abs(newPointePos - selectedCheckerOrigBoardPos) == rolledValues[0]) { usedRoll1 = true; getLegalMoves(-1, rolledValues[1]); } else { usedRoll2 = true; getLegalMoves(rolledValues[0], -1); } } else { selectedChecker.transform.position = selectedCheckerOrigPos; } selectedChecker = null; selectedCheckerOrigPos = Vector3.zero; selectedCheckerOrigBoardPos = -1; resetPointes(); }
//This will store in a list all possible moves given two rolls and the current game state private void getLegalMoves(int roll1, int roll2) { //Rolls 1 and 2 List <KeyValuePair <int, int> > movesRoll1 = new List <KeyValuePair <int, int> >(); List <KeyValuePair <int, int> > movesRoll2 = new List <KeyValuePair <int, int> >(); legalMoves.Clear(); if (currGamePhase == turnPhase.WhiteTurn) { if (whiteCheckerPhase == gamePhase.BaringOff) { if (!usedRoll1) { movesRoll1 = getBarringOffMoves(roll1, roll2, true); } if (!usedRoll2) { movesRoll2 = getBarringOffMoves(roll2, roll1, true); } } else { if (!usedRoll1) { movesRoll1 = getRegularMoves(roll1, roll2, true); } if (!usedRoll2) { movesRoll2 = getRegularMoves(roll2, roll1, true); } //In certain situations, there are edge cases to consider for legal moves. Only such edge case occurs when we haven't used either roll and one of the rolls isn't usable yet if (!usedRoll1 && !usedRoll2) { int numRoll1Moves = movesRoll1.Count; int numRoll2Moves = movesRoll2.Count; if (numRoll1Moves == 0 && numRoll2Moves > 1) { movesRoll2 = refineRegularMoves(movesRoll2, roll1, true); } else if (numRoll2Moves == 0 && numRoll1Moves > 1) { movesRoll1 = refineRegularMoves(movesRoll1, roll2, true); } } } } else { if (blackCheckerPhase == gamePhase.BaringOff) { if (!usedRoll1) { movesRoll1 = getBarringOffMoves(roll1, roll2, false); } if (!usedRoll2) { movesRoll2 = getBarringOffMoves(roll2, roll1, false); } } else { if (!usedRoll1) { movesRoll1 = getRegularMoves(roll1, roll2, false); } if (!usedRoll2) { movesRoll2 = getRegularMoves(roll2, roll1, false); } if (!usedRoll1 && !usedRoll2) { int numRoll1Moves = movesRoll1.Count; int numRoll2Moves = movesRoll2.Count; if (numRoll1Moves == 0 && numRoll2Moves > 1) { movesRoll2 = refineRegularMoves(movesRoll2, roll1, false); } else if (numRoll2Moves == 0 && numRoll1Moves > 1) { movesRoll1 = refineRegularMoves(movesRoll1, roll2, false); } } } } //Once we have gotten each possible move for both rolls, add it to legalmoves so it can be highlighted foreach (var move in movesRoll1) { legalMoves.Add(move); } foreach (var move in movesRoll2) { legalMoves.Add(move); } //If no legal moves, turn over and update game state if (legalMoves.Count == 0) { //Switch sides dice.resetDicePos(); if (currGamePhase == turnPhase.WhiteTurn) { currGamePhase = turnPhase.BlackTurn; if (againstAI) { rolledValues = dice.throwDice(true); StartCoroutine(doAIMove()); currGamePhase = turnPhase.WhiteTurn; } } else { currGamePhase = turnPhase.WhiteTurn; } } else { //Highlight moveable checkers highlightCheckersMoveable(); } }