Skip to content

Commit

Permalink
Convert to Swift 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinCoble committed Sep 16, 2016
1 parent a0e90d7 commit 1affe99
Show file tree
Hide file tree
Showing 66 changed files with 3,500 additions and 3,486 deletions.
19 changes: 16 additions & 3 deletions AIToolbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Kevin Coble";
TargetAttributes = {
0E0A4F921C133E8800AD5AAE = {
Expand All @@ -507,9 +507,11 @@
};
0EBA29AA1A91350C0012CEC9 = {
CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0800;
};
0EBA29B51A91350C0012CEC9 = {
CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -728,7 +730,7 @@
0E0A4FA41C133E8800AD5AAE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -749,7 +751,7 @@
0E0A4FA51C133E8800AD5AAE /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down Expand Up @@ -810,8 +812,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
Expand All @@ -821,6 +825,7 @@
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -856,8 +861,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
Expand All @@ -866,6 +873,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -875,6 +883,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -898,6 +907,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -918,6 +928,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.MacRobotics.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -942,6 +953,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.MacRobotics.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -962,6 +974,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.MacRobotics.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
30 changes: 15 additions & 15 deletions AIToolbox/AlphaBeta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@
import Foundation

/// Subclass AlphaBetaNode to provide move generation and static evaluation routines
public class AlphaBetaNode {
open class AlphaBetaNode {

public init() {
}

public func generateMoves(forMaximizer: Bool) -> [AlphaBetaNode] {
open func generateMoves(_ forMaximizer: Bool) -> [AlphaBetaNode] {
return []
}

public func staticEvaluation() -> Double {
open func staticEvaluation() -> Double {
return 0.0
}
}

public class AlphaBetaGraph {
open class AlphaBetaGraph {

public init() {
}

public func startAlphaBetaWithNode(startNode: AlphaBetaNode, forDepth: Int, startingAsMaximizer : Bool = true) -> AlphaBetaNode? {
open func startAlphaBetaWithNode(_ startNode: AlphaBetaNode, forDepth: Int, startingAsMaximizer : Bool = true) -> AlphaBetaNode? {
// Start the recursion
let α = -Double.infinity
let β = Double.infinity
return alphaBeta(startNode, remainingDepth: forDepth, alpha: α, beta : β, maximizer: startingAsMaximizer, topLevel: true).winningNode
}

func alphaBeta(currentNode: AlphaBetaNode, remainingDepth: Int, alpha : Double, beta : Double, maximizer: Bool, topLevel : Bool) -> (value: Double, winningNode: AlphaBetaNode?) {
func alphaBeta(_ currentNode: AlphaBetaNode, remainingDepth: Int, alpha : Double, beta : Double, maximizer: Bool, topLevel : Bool) -> (value: Double, winningNode: AlphaBetaNode?) {
// if this is a leaf node, return the static evaluation
if (remainingDepth == 0) {
return (value: currentNode.staticEvaluation(), winningNode: currentNode)
Expand Down Expand Up @@ -102,14 +102,14 @@ public class AlphaBetaGraph {
}
}

public func startAlphaBetaConcurrentWithNode(startNode: AlphaBetaNode, forDepth: Int, startingAsMaximizer : Bool = true) -> AlphaBetaNode? {
open func startAlphaBetaConcurrentWithNode(_ startNode: AlphaBetaNode, forDepth: Int, startingAsMaximizer : Bool = true) -> AlphaBetaNode? {
// Start the recursion
let α = -Double.infinity
let β = Double.infinity
return alphaBetaConcurrent(startNode, remainingDepth: forDepth, alpha: α, beta : β, maximizer: startingAsMaximizer, topLevel: true).winningNode
}

func alphaBetaConcurrent(currentNode: AlphaBetaNode, remainingDepth: Int, alpha : Double, beta : Double, maximizer: Bool, topLevel : Bool) -> (value: Double, winningNode: AlphaBetaNode?) {
func alphaBetaConcurrent(_ currentNode: AlphaBetaNode, remainingDepth: Int, alpha : Double, beta : Double, maximizer: Bool, topLevel : Bool) -> (value: Double, winningNode: AlphaBetaNode?) {
// if this is a leaf node, return the static evaluation
if (remainingDepth == 0) {
return (value: currentNode.staticEvaluation(), winningNode: currentNode)
Expand All @@ -130,11 +130,11 @@ public class AlphaBetaGraph {
}

// Create the value array
var childValues : [Double] = Array(count: children.count, repeatedValue: 0.0)
var childValues : [Double] = Array(repeating: 0.0, count: children.count)

// Get the concurrent queue and group
let tQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
let tGroup = dispatch_group_create()
let tQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default)
let tGroup = DispatchGroup()

var winningNode : AlphaBetaNode?

Expand All @@ -154,13 +154,13 @@ public class AlphaBetaGraph {
// Iterate through the rest of the child nodes
if (children.count > 1) {
for index in 1..<children.count {
dispatch_group_async(tGroup, tQueue, {() -> Void in
tQueue.async(group: tGroup, execute: {() -> Void in
childValues[index] = self.alphaBetaConcurrent(children[index], remainingDepth: nextDepth, alpha: α, beta: β, maximizer: false, topLevel: false).value
})
}

// Wait for the evaluations
dispatch_group_wait(tGroup, DISPATCH_TIME_FOREVER)
tGroup.wait()

// Prune and find best
for index in 1..<children.count {
Expand Down Expand Up @@ -192,13 +192,13 @@ public class AlphaBetaGraph {
// Iterate through the rest of the child nodes
if (children.count > 1) {
for index in 1..<children.count {
dispatch_group_async(tGroup, tQueue, {() -> Void in
tQueue.async(group: tGroup, execute: {() -> Void in
childValues[index] = self.alphaBetaConcurrent(children[index], remainingDepth: nextDepth, alpha: α, beta: β, maximizer: true, topLevel: false).value
})
}

// Wait for the evaluations
dispatch_group_wait(tGroup, DISPATCH_TIME_FOREVER)
tGroup.wait()

// Prune and find best
for index in 1..<children.count {
Expand Down
Loading

0 comments on commit 1affe99

Please sign in to comment.