Category talk

Difference between revisions of "Shuffle"

From Shadow Era Wiki

m
m
Line 31: Line 31:
 
! colspan="2" | <center>DETAILED CODE</center>
 
! colspan="2" | <center>DETAILED CODE</center>
 
|-
 
|-
 +
| This code is a collection of all the functions involved in the shuffle mechanic, though it doesn't exist as a single block in any one file.<br>
 +
'''The complete shuffle logic is primarily found in GameModel.cs.'''
 +
|-
 +
<small><syntaxhighlight lang="csharp">
 +
// GameModel.cs
 +
public static void ShuffleDeck(int side) {
 +
    // Logic for shuffling the deck for the specified player side
 +
    Random.State state = Random.state; // Save the current random state
 +
    Random.InitState(num); // Initialize random state with a seed
 +
    int index = Random.Range(0, model.players[side].deck.Count); // Get a random index
 +
    OnDeckShuffled(side); // Call deck shuffled event
 +
    gameData.shuffledDeckThisTurn[side]++; // Increment the shuffle counter
 +
    Random.state = state; // Restore the previous random state
 +
    Debug.Log("Shuffled deck for side " + side + ", seed " + num); // Log shuffle info
 +
}
  
 +
public static void ShuffleDeck() {
 +
    ShuffleDeck(CurSide()); // Calls the shuffle method for the current player side
 +
}
 +
 +
// Additional functions related to deck manipulation
 +
public static void RemoveDeck(ShadowEraCard card) {
 +
    // Logic for removing a card from the deck
 +
}
 +
 +
// GameController.cs
 +
GameModel.ShuffleDeck(); // Called to trigger the shuffle process
 +
GameModel.GameStateActivate(GameState.GameStateType.mulliganDraw); // Changes the game state for a mulligan
 +
 +
// Gameplay.cs
 +
GameModel.ShuffleDeck(1); // Executes the shuffle for player 1
 +
 +
// GameState.cs
 +
case GameStateType.draw: {
 +
    // Logic for handling the draw state after a shuffle
 +
}
 +
 +
case GameStateType.mulliganDraw: {
 +
    // Logic for handling the mulligan draw state, ensuring shuffle occurs correctly
 +
}
 +
 +
</syntaxhighlight></small>
 
|}
 
|}

Revision as of 19:28, 2 October 2024


Code Summary and Detailed Code

// GameModel.cs
public static void ShuffleDeck(int side) {
    // Logic for shuffling the deck for the specified player side
    Random.State state = Random.state; // Save the current random state
    Random.InitState(num); // Initialize random state with a seed
    int index = Random.Range(0, model.players[side].deck.Count); // Get a random index
    OnDeckShuffled(side); // Call deck shuffled event
    gameData.shuffledDeckThisTurn[side]++; // Increment the shuffle counter
    Random.state = state; // Restore the previous random state
    Debug.Log("Shuffled deck for side " + side + ", seed " + num); // Log shuffle info
}
 
public static void ShuffleDeck() {
    ShuffleDeck(CurSide()); // Calls the shuffle method for the current player side
}
 
// Additional functions related to deck manipulation
public static void RemoveDeck(ShadowEraCard card) {
    // Logic for removing a card from the deck
}
 
// GameController.cs
GameModel.ShuffleDeck(); // Called to trigger the shuffle process
GameModel.GameStateActivate(GameState.GameStateType.mulliganDraw); // Changes the game state for a mulligan
 
// Gameplay.cs
GameModel.ShuffleDeck(1); // Executes the shuffle for player 1
 
// GameState.cs
case GameStateType.draw: {
    // Logic for handling the draw state after a shuffle
}
 
case GameStateType.mulliganDraw: {
    // Logic for handling the mulligan draw state, ensuring shuffle occurs correctly
}
FILE REFERENCES IN THE GAME
TERMS TO LOCATE SHUFFLE REFERENCE
  • GameModel.cs: Contains the main logic for managing the deck and card operations, including shuffling:
    `public static void ShuffleDeck(int side)`, `public static void ShuffleDeck()`, `gameData.shuffledDeckThisTurn[side]++`.

  • GameController.cs: Handles game events and triggers deck shuffling and state changes:
    `GameModel.ShuffleDeck()`, `GameModel.GameStateActivate(GameState.GameStateType.mulliganDraw)`.

  • Gameplay.cs: Manages the flow of the game, including player interactions and calling shuffle methods:
    `GameModel.ShuffleDeck(1)`.

  • GameController.cs: Defines game states and manages the logic for drawing and shuffling based on state transitions:
    `case GameStateType.draw:`, `case GameStateType.mulliganDraw:`.

  • Shuffle
  • Deck
  • Randomness
  • GameState
  • ShuffleDeck
SUMMARY OF THE SHUFFLE PROCESS:
  1. `ShuffleDeck(int side)` :
    Handles the shuffling of the deck for the specified player side.
  2. `ShuffleDeck()` :
    Calls the shuffle method for the current player side.
  3. `gameData.shuffledDeckThisTurn[side]++` :
    Increments the shuffle counter for the current turn for the specified player side.
  4. `GameModel.ShuffleDeck()` :
    Called in the game controller to trigger the shuffle process.
  5. `GameModel.GameStateActivate(GameState.GameStateType.mulliganDraw)` :
    Changes the game state to allow for a mulligan, influencing when the shuffle occurs.
  6. `GameModel.ShuffleDeck(1)` :
    Executes the shuffle for player 1, ensuring that their deck is mixed before drawing.
  7. `case GameStateType.draw:` :
    Logic for handling the draw state, ensuring that the game responds appropriately after a shuffle.
  8. `case GameStateType.mulliganDraw:` :
    Logic for handling the mulligan draw state, ensuring that the shuffle occurs correctly.
DETAILED CODE
This code is a collection of all the functions involved in the shuffle mechanic, though it doesn't exist as a single block in any one file.

The complete shuffle logic is primarily found in GameModel.cs.