import type { FieldSize } from '@/scripts/interfaces/FieldSize.ts'

class LocalGame {
  public field: number[][]

  private currentPlayer: number = 1;
  constructor(fieldSize: FieldSize) {
    this.field = Array.from({ length: fieldSize.y }, () => Array(fieldSize.x).fill(0))
  }

  place(locationX: number | null): void {
    if(locationX === null) return;
    console.log(
      `Player ${this.currentPlayer} placed a field at x: ${locationX}`
    )
    for (let y = this.field.length - 1; y >= 0; y--) {
      const row = this.field[y]

      if (row && row[locationX] === 0) {
        row[locationX] = this.currentPlayer
        this.currentPlayer = this.currentPlayer === 1 ? 2 : 1
        break
      }
    }

  }
}

export default LocalGame