|
|
|
@ -101,21 +101,18 @@ public struct FourInARowRules: Rules {
|
|
|
|
|
internal static func rowOfLengthWin(board: Board, last_turn: Player?, minimum_aligned: Int, players: [Player]) -> GameState {
|
|
|
|
|
var occupied = 0
|
|
|
|
|
|
|
|
|
|
for column in 0..<board.columns {
|
|
|
|
|
for row in 0..<board.rows {
|
|
|
|
|
let current = Coords(column, row)
|
|
|
|
|
guard let piece = board[current] else { continue }
|
|
|
|
|
|
|
|
|
|
occupied += 1
|
|
|
|
|
for current in board.coords {
|
|
|
|
|
guard let piece = board[current] else { continue }
|
|
|
|
|
|
|
|
|
|
occupied += 1
|
|
|
|
|
|
|
|
|
|
// For each "axis" (described as one direction)
|
|
|
|
|
for dir: (Int, Int) in [(1, 0), (0, 1), (1, 1), (-1, 1)] {
|
|
|
|
|
let cells = Self.row(center: current, board: board, dir: dir)
|
|
|
|
|
|
|
|
|
|
// For each "axis" (described as one direction)
|
|
|
|
|
for dir: (Int, Int) in [(1, 0), (0, 1), (1, 1), (-1, 1)] {
|
|
|
|
|
let cells = Self.row(center: current, board: board, dir: dir)
|
|
|
|
|
|
|
|
|
|
if cells.count >= minimum_aligned {
|
|
|
|
|
let player = players.first(where: { $0.piece_type == piece.type })!
|
|
|
|
|
return GameState.Win(winner: player, board: board, cells: cells)
|
|
|
|
|
}
|
|
|
|
|
if cells.count >= minimum_aligned {
|
|
|
|
|
let player = players.first(where: { $0.piece_type == piece.type })!
|
|
|
|
|
return GameState.Win(winner: player, board: board, cells: cells)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -128,41 +125,6 @@ public struct FourInARowRules: Rules {
|
|
|
|
|
return .Playing(turn: players.first!)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* public mutating func onMoveDone(move: Move, board: Board) -> Void {
|
|
|
|
|
// self.history.append(move)
|
|
|
|
|
|
|
|
|
|
switch move.action {
|
|
|
|
|
case .InsertOnSide(side: .Top, let offset):
|
|
|
|
|
let initCoords = board.getInsertionCoordinates(from: .Top, offset: offset)
|
|
|
|
|
let pieceCoords = switch board.fallCoordinates(
|
|
|
|
|
initialCoords: initCoords,
|
|
|
|
|
direction: .Bottom
|
|
|
|
|
) {
|
|
|
|
|
case .Occupied:
|
|
|
|
|
initCoords
|
|
|
|
|
case .Piece(_, let touched):
|
|
|
|
|
touched
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fatalError("Illegal move \(move.action)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Self.countMaxRow(center: pieceCoords, board: board) >= self.minAligned {
|
|
|
|
|
self.state = .Finished(winner: move.player)
|
|
|
|
|
} else if board.countPieces() == board.columns * board.rows {
|
|
|
|
|
self.state = .Finished(winner: nil)
|
|
|
|
|
} else {
|
|
|
|
|
let next: PieceType = switch move.player {
|
|
|
|
|
case .A: .B
|
|
|
|
|
case .B: .A
|
|
|
|
|
}
|
|
|
|
|
self.state = .Playing(turn: next)
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
fatalError("Illegal move \(move.action)")
|
|
|
|
|
}
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
@available(*, deprecated, message: "Old Rules design remnents")
|
|
|
|
|
internal static func countMaxRow(center: Coords, board: Board) -> Int {
|
|
|
|
|