override fallbackFn()

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


  override fallbackFn(): Signs {
    let nextLikely;

    // Add to markov chain from previous moves
    const lastPlayed = this.getLastPlayed();

    this.buildMarkovChain(lastPlayed);

    if (
      this.gameHandler.pastPlayerMoves().length > 1 &&
      lastPlayed &&
      this.markovChain[lastPlayed]
    ) {
      for (const key in this.markovChain[lastPlayed]) {
        if (!nextLikely) {
          nextLikely = key;
        } else {
          if (
            this.markovChain[lastPlayed][key].occurrences >
            this.markovChain[lastPlayed][nextLikely].occurrences
          ) {
            nextLikely = key;
          }
        }
      }
    }
    if (!nextLikely) {
      // Couldn't predict from the chain, pick randomly
      return this.getRandomSign();
    } else {
      return this.getWinningSign(nextLikely as Signs);
    }
  }