//
//  TicTacToeBoard.swift
//  TTTKit
//
//  Created by Shadowfacts on 12/21/22.
//

import Foundation

public struct TicTacToeBoard: Board {
    private var marks: [[Mark?]] = [
        [nil, nil, nil],
        [nil, nil, nil],
        [nil, nil, nil],
    ]
    
    init() {
    }
    
    init(marks: [[Mark?]]) {
        precondition(marks.count == 3)
        precondition(marks.allSatisfy { $0.count == 3 })
        self.marks = marks
    }
    
    public subscript(_ column: Int, _ row: Int) -> Mark? {
        get {
            marks[row][column]
        }
    }
    
    public func canPlay(column: Int, row: Int) -> Bool {
        return self[column, row] == nil
    }
    
    public mutating func play(mark: Mark, column: Int, row: Int) {
        marks[row][column] = mark
    }
}
