This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getBestMove(players: [Player], whoseTurn: Player, position: Board) async -> Move? { | |
| var best: Move? | |
| switch appState.game.aiType { | |
| case .random: | |
| best = getRandomMove(moves: position.generateMoves(player: whoseTurn)) | |
| case .kamikaze: | |
| best = miniMax(position: position, players: players, whoseTurn: players[1], depth: 0) | |
| case .minimax: | |
| best = miniMax(position: position, players: players, whoseTurn: players[1], depth: appState.searchDepth) | |
| case .pruner: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public func generateMoves(player: Player) -> [Move] | |
| { | |
| var moves = [Move]() | |
| for rank in 0..<squaresHigh { | |
| for file in 0..<squaresWide { | |
| if let man = squares[file][rank].man { | |
| if man.player == player { | |
| moves += (man.generateMoves(board: self, x: file, y: rank)) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct GhostModifier: ViewModifier { | |
| let hasGhost: Bool | |
| let isInAWall: Bool | |
| func body(content: Content) -> some View { | |
| if hasGhost { | |
| if isInAWall { | |
| content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func blockedByWall(man: Man, targetSquare: Square) -> Bool { | |
| return targetSquare.squareType == .wall && !man.tools.contains(.ghost) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| squareView(file: file, rank: rank, color: viewModel.getBackgroundColor(file: file, rank: rank)) | |
| .artifactModifier(tool: viewModel.showTool(file: file, rank: rank), squareSize: viewModel.squareSize) | |
| .handoffableModifier(isHighlighted: viewModel.handOffable[file][rank]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct HandoffableModifier: ViewModifier { | |
| let isHighlighted: Bool | |
| func body(content: Content) -> some View { | |
| if isHighlighted { | |
| ZStack { | |
| GeometryReader { geometry in | |
| content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func markHandoffableSquares() { | |
| // the piece handing off the tool can't hand it to itself | |
| notHandOffable[moveStart!.0][moveStart!.1] = true | |
| var handoffables = [(moveStart!.0, moveStart!.1)] | |
| repeat { | |
| handoffables = markHandoffablesAndReturnNextSet(handoffables) | |
| } while !handoffables.isEmpty | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getHandoffableNeighbors(file: Int, rank: Int) -> [(Int, Int)] { | |
| var neighbors: [(Int, Int)] = [(Int, Int)]() | |
| for i in file - 1...file + 1 { | |
| for j in rank - 1...rank + 1 { | |
| if i >= 0 && i < board.squaresWide && j >= 0 && j < board.squaresHigh { | |
| if !(i == file && j == rank) { | |
| if !(handOffable[i][j] || notHandOffable[i][j]) { | |
| if board.squares[i][j].man == nil { | |
| notHandOffable[i][j] = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func markSquare(file: Int, rank: Int) { | |
| if file >= 0 && file < board.squaresWide && rank >= 0 && rank < board.squaresHigh { | |
| if !handOffable[file][rank] && !notHandOffable[file][rank] { | |
| if board.squares[file][rank].man == nil { | |
| notHandOffable[file][rank] = true | |
| } | |
| else if board.squares[file][rank].man!.player != board.whoseTurn { | |
| notHandOffable[file][rank] = true | |
| } | |
| else { |
NewerOlder