|
|
|
@ -101,9 +101,7 @@ 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)
|
|
|
|
|
for current in board.coords {
|
|
|
|
|
guard let piece = board[current] else { continue }
|
|
|
|
|
|
|
|
|
|
occupied += 1
|
|
|
|
@ -118,7 +116,6 @@ public struct FourInARowRules: Rules {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if occupied == board.columns * board.rows {
|
|
|
|
|
return .Draw
|
|
|
|
@ -129,41 +126,6 @@ public struct FourInARowRules: Rules {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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 {
|
|
|
|
|
var maxLength = 0
|
|
|
|
|