private buildMarkovChain()

in src/app/pages/game/services/ai-strategies/markov-strategy.service.ts [104:118]


  private buildMarkovChain(lastPlayed: Signs | undefined): void {
    if (this.gameHandler.pastPlayerMoves().length >= 2 && lastPlayed) {
      const pastMove =
        this.gameHandler.pastPlayerMoves()[this.gameHandler.pastPlayerMoves().length - 2].name;
      if (!this.markovChain[pastMove]) {
        this.markovChain[pastMove] = {};
      }
      if (!this.markovChain[pastMove][lastPlayed]) {
        this.markovChain[pastMove][lastPlayed] = {occurrences: 1};
      } else {
        this.markovChain[pastMove][lastPlayed].occurrences =
          this.markovChain[pastMove][lastPlayed].occurrences + 1;
      }
    }
  }