Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0371a5d064 | |||
| aa31427b5f | |||
| 2694a19834 | |||
| 46d9b051ab | |||
| fc5a5ed5ac | |||
| beed7797b4 | |||
| 5b6255f58f | |||
| e2782cc397 | |||
| 1c4e3c1973 | |||
| 8c138eb699 | |||
| b8ed2b3156 | |||
| 6fdd41c305 | |||
| 275489be73 |
+1
-1
@@ -1 +1 @@
|
||||
3.0
|
||||
4.0
|
||||
@@ -0,0 +1,8 @@
|
||||
disabled_rules:
|
||||
- trailing_whitespace
|
||||
- cyclomatic_complexity
|
||||
- nesting
|
||||
- type_name
|
||||
- force_cast
|
||||
- identifier_name
|
||||
- unused_closure_parameter
|
||||
@@ -13,7 +13,6 @@
|
||||
671989911DFFE8650053EA3D /* BoardRaterCenterDominanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 671989901DFFE8650053EA3D /* BoardRaterCenterDominanceTests.swift */; };
|
||||
673B95191E4CE5880086CA97 /* BoardRaterThreatenedPiecesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09A4C0281E013ECB000CFBF4 /* BoardRaterThreatenedPiecesTests.swift */; };
|
||||
676902581E432380007C76D7 /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 676902571E432380007C76D7 /* PerformanceTests.swift */; };
|
||||
676C911B1E478A3A00985A4F /* SwiftChess.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A9CA0D1DE64D6500510FB8 /* SwiftChess.framework */; };
|
||||
676C911C1E478A3A00985A4F /* SwiftChess.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 67A9CA0D1DE64D6500510FB8 /* SwiftChess.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
676EF7C51E15AC1700E275B4 /* BoardRaterKingSurroundingPossession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 676EF7C41E15AC1700E275B4 /* BoardRaterKingSurroundingPossession.swift */; };
|
||||
67A3EB161E3A926C00F6F01B /* BoardScenarios.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A3EB121E3A826800F6F01B /* BoardScenarios.swift */; };
|
||||
@@ -25,7 +24,6 @@
|
||||
67A9CA391DE64E0900510FB8 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
|
||||
67A9CA3A1DE64E0E00510FB8 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
|
||||
67A9CA3C1DE64E2B00510FB8 /* SwiftChess.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A9CA0D1DE64D6500510FB8 /* SwiftChess.framework */; };
|
||||
67A9CA3D1DE64E7100510FB8 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 607FACEA1AFB9204008FA782 /* Info.plist */; };
|
||||
67B73A9B1E15351900C19176 /* PromotionSelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B73A9A1E15351900C19176 /* PromotionSelectionViewController.swift */; };
|
||||
67B73A9F1E154C1E00C19176 /* AIPlayerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B73A9E1E154C1E00C19176 /* AIPlayerTests.swift */; };
|
||||
67D54A5D1DE7682D00C12258 /* BoardTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67D54A511DE7680E00C12258 /* BoardTests.swift */; };
|
||||
@@ -133,7 +131,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
67A9CA3C1DE64E2B00510FB8 /* SwiftChess.framework in Frameworks */,
|
||||
676C911B1E478A3A00985A4F /* SwiftChess.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -274,6 +271,7 @@
|
||||
67A9CA111DE64DAA00510FB8 /* Frameworks */,
|
||||
67A9CA121DE64DAA00510FB8 /* Resources */,
|
||||
676C911F1E478A3A00985A4F /* Embed Frameworks */,
|
||||
677F42131F9DCE4C00BBD071 /* Swift Lint */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@@ -292,6 +290,7 @@
|
||||
67A9CA231DE64DAA00510FB8 /* Sources */,
|
||||
67A9CA241DE64DAA00510FB8 /* Frameworks */,
|
||||
67A9CA251DE64DAA00510FB8 /* Resources */,
|
||||
677F42111F9DCD9A00BBD071 /* Swift Lint */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@@ -310,16 +309,18 @@
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0800;
|
||||
LastUpgradeCheck = 0800;
|
||||
LastUpgradeCheck = 0900;
|
||||
ORGANIZATIONNAME = CocoaPods;
|
||||
TargetAttributes = {
|
||||
67A9CA131DE64DAA00510FB8 = {
|
||||
CreatedOnToolsVersion = 8.0;
|
||||
DevelopmentTeam = VAA3W4LPY2;
|
||||
LastSwiftMigration = 0900;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
67A9CA261DE64DAA00510FB8 = {
|
||||
CreatedOnToolsVersion = 8.0;
|
||||
LastSwiftMigration = 0900;
|
||||
ProvisioningStyle = Automatic;
|
||||
TestTargetID = 67A9CA131DE64DAA00510FB8;
|
||||
};
|
||||
@@ -382,12 +383,42 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
67A9CA3D1DE64E7100510FB8 /* Info.plist in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
677F42111F9DCD9A00BBD071 /* Swift Lint */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
);
|
||||
name = "Swift Lint";
|
||||
outputPaths = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
|
||||
};
|
||||
677F42131F9DCE4C00BBD071 /* Swift Lint */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
);
|
||||
name = "Swift Lint";
|
||||
outputPaths = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
67A9CA101DE64DAA00510FB8 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
@@ -473,14 +504,20 @@
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
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_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
@@ -520,14 +557,20 @@
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
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_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
@@ -568,7 +611,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.SwiftChessExample;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_VERSION = 3.0;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Debug;
|
||||
@@ -587,7 +630,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.SwiftChessExample;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Release;
|
||||
@@ -607,7 +650,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.SwiftChessExampleTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_VERSION = 3.0;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftChessExample.app/SwiftChessExample";
|
||||
};
|
||||
name = Debug;
|
||||
@@ -625,7 +668,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.SwiftChessExampleTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftChessExample.app/SwiftChessExample";
|
||||
};
|
||||
name = Release;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0800"
|
||||
LastUpgradeVersion = "0900"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -40,6 +40,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
@@ -69,6 +70,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
language = ""
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
use_frameworks!
|
||||
|
||||
target 'SwiftChess_Example' do
|
||||
pod 'SwiftChess', :path => '../'
|
||||
|
||||
# target 'SwiftChess_Tests' do
|
||||
# inherit! :search_paths
|
||||
|
||||
|
||||
#end
|
||||
end
|
||||
|
||||
target 'SwiftChess_Tests' do
|
||||
pod 'SwiftChess', :path => '../'
|
||||
end
|
||||
|
||||
post_install do |installer|
|
||||
installer.pods_project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['SWIFT_VERSION'] = '3.0'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
PODS:
|
||||
- SwiftChess (0.1.0)
|
||||
|
||||
DEPENDENCIES:
|
||||
- SwiftChess (from `../`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
SwiftChess:
|
||||
:path: ../
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
SwiftChess: 7ec2077f755647df70261575a0546c0486930cf3
|
||||
|
||||
PODFILE CHECKSUM: 410ba32ae65123335cc9534558e1f605ee0bf56c
|
||||
|
||||
COCOAPODS: 1.0.1
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "SwiftChess",
|
||||
"version": "0.1.0",
|
||||
"summary": "A short description of SwiftChess.",
|
||||
"description": "TODO: Add long description of the pod here.",
|
||||
"homepage": "https://github.com/<GITHUB_USERNAME>/SwiftChess",
|
||||
"license": {
|
||||
"type": "MIT",
|
||||
"file": "LICENSE"
|
||||
},
|
||||
"authors": {
|
||||
"Steve Barnegren": "steve.barnegren@gmail.com"
|
||||
},
|
||||
"source": {
|
||||
"git": "https://github.com/<GITHUB_USERNAME>/SwiftChess.git",
|
||||
"tag": "0.1.0"
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "8.0"
|
||||
},
|
||||
"source_files": "SwiftChess/Classes/**/*"
|
||||
}
|
||||
Generated
-16
@@ -1,16 +0,0 @@
|
||||
PODS:
|
||||
- SwiftChess (0.1.0)
|
||||
|
||||
DEPENDENCIES:
|
||||
- SwiftChess (from `../`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
SwiftChess:
|
||||
:path: ../
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
SwiftChess: 7ec2077f755647df70261575a0546c0486930cf3
|
||||
|
||||
PODFILE CHECKSUM: 410ba32ae65123335cc9534558e1f605ee0bf56c
|
||||
|
||||
COCOAPODS: 1.0.1
|
||||
-1737
File diff suppressed because it is too large
Load Diff
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
# Acknowledgements
|
||||
This application makes use of the following third party libraries:
|
||||
|
||||
## SwiftChess
|
||||
|
||||
Copyright (c) 2016 Steve Barnegren <steve.barnegren@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
Generated by CocoaPods - https://cocoapods.org
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>PreferenceSpecifiers</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>This application makes use of the following third party libraries:</string>
|
||||
<key>Title</key>
|
||||
<string>Acknowledgements</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Copyright (c) 2016 Steve Barnegren <steve.barnegren@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>SwiftChess</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Generated by CocoaPods - https://cocoapods.org</string>
|
||||
<key>Title</key>
|
||||
<string></string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>StringsTable</key>
|
||||
<string>Acknowledgements</string>
|
||||
<key>Title</key>
|
||||
<string>Acknowledgements</string>
|
||||
</dict>
|
||||
</plist>
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
@interface PodsDummy_Pods_SwiftChess_Example : NSObject
|
||||
@end
|
||||
@implementation PodsDummy_Pods_SwiftChess_Example
|
||||
@end
|
||||
Generated
-91
@@ -1,91 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
|
||||
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
|
||||
|
||||
install_framework()
|
||||
{
|
||||
if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
|
||||
local source="${BUILT_PRODUCTS_DIR}/$1"
|
||||
elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
|
||||
local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
|
||||
elif [ -r "$1" ]; then
|
||||
local source="$1"
|
||||
fi
|
||||
|
||||
local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
|
||||
if [ -L "${source}" ]; then
|
||||
echo "Symlinked..."
|
||||
source="$(readlink "${source}")"
|
||||
fi
|
||||
|
||||
# use filter instead of exclude so missing patterns dont' throw errors
|
||||
echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
|
||||
rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"
|
||||
|
||||
local basename
|
||||
basename="$(basename -s .framework "$1")"
|
||||
binary="${destination}/${basename}.framework/${basename}"
|
||||
if ! [ -r "$binary" ]; then
|
||||
binary="${destination}/${basename}"
|
||||
fi
|
||||
|
||||
# Strip invalid architectures so "fat" simulator / device frameworks work on device
|
||||
if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
|
||||
strip_invalid_archs "$binary"
|
||||
fi
|
||||
|
||||
# Resign the code if required by the build settings to avoid unstable apps
|
||||
code_sign_if_enabled "${destination}/$(basename "$1")"
|
||||
|
||||
# Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
|
||||
if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
|
||||
local swift_runtime_libs
|
||||
swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]})
|
||||
for lib in $swift_runtime_libs; do
|
||||
echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
|
||||
rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
|
||||
code_sign_if_enabled "${destination}/${lib}"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Signs a framework with the provided identity
|
||||
code_sign_if_enabled() {
|
||||
if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then
|
||||
# Use the current code_sign_identitiy
|
||||
echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
|
||||
echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements \"$1\""
|
||||
/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Strip invalid architectures
|
||||
strip_invalid_archs() {
|
||||
binary="$1"
|
||||
# Get architectures for current file
|
||||
archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)"
|
||||
stripped=""
|
||||
for arch in $archs; do
|
||||
if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then
|
||||
# Strip non-valid architectures in-place
|
||||
lipo -remove "$arch" -output "$binary" "$binary" || exit 1
|
||||
stripped="$stripped $arch"
|
||||
fi
|
||||
done
|
||||
if [[ "$stripped" ]]; then
|
||||
echo "Stripped $binary of architectures:$stripped"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
if [[ "$CONFIGURATION" == "Debug" ]]; then
|
||||
install_framework "$BUILT_PRODUCTS_DIR/SwiftChess/SwiftChess.framework"
|
||||
fi
|
||||
if [[ "$CONFIGURATION" == "Release" ]]; then
|
||||
install_framework "$BUILT_PRODUCTS_DIR/SwiftChess/SwiftChess.framework"
|
||||
fi
|
||||
Generated
-102
@@ -1,102 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
|
||||
RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt
|
||||
> "$RESOURCES_TO_COPY"
|
||||
|
||||
XCASSET_FILES=()
|
||||
|
||||
case "${TARGETED_DEVICE_FAMILY}" in
|
||||
1,2)
|
||||
TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone"
|
||||
;;
|
||||
1)
|
||||
TARGET_DEVICE_ARGS="--target-device iphone"
|
||||
;;
|
||||
2)
|
||||
TARGET_DEVICE_ARGS="--target-device ipad"
|
||||
;;
|
||||
*)
|
||||
TARGET_DEVICE_ARGS="--target-device mac"
|
||||
;;
|
||||
esac
|
||||
|
||||
realpath() {
|
||||
DIRECTORY="$(cd "${1%/*}" && pwd)"
|
||||
FILENAME="${1##*/}"
|
||||
echo "$DIRECTORY/$FILENAME"
|
||||
}
|
||||
|
||||
install_resource()
|
||||
{
|
||||
if [[ "$1" = /* ]] ; then
|
||||
RESOURCE_PATH="$1"
|
||||
else
|
||||
RESOURCE_PATH="${PODS_ROOT}/$1"
|
||||
fi
|
||||
if [[ ! -e "$RESOURCE_PATH" ]] ; then
|
||||
cat << EOM
|
||||
error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script.
|
||||
EOM
|
||||
exit 1
|
||||
fi
|
||||
case $RESOURCE_PATH in
|
||||
*.storyboard)
|
||||
echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}"
|
||||
ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS}
|
||||
;;
|
||||
*.xib)
|
||||
echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}"
|
||||
ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS}
|
||||
;;
|
||||
*.framework)
|
||||
echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
echo "rsync -av $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
rsync -av "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
;;
|
||||
*.xcdatamodel)
|
||||
echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\""
|
||||
xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom"
|
||||
;;
|
||||
*.xcdatamodeld)
|
||||
echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\""
|
||||
xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd"
|
||||
;;
|
||||
*.xcmappingmodel)
|
||||
echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\""
|
||||
xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm"
|
||||
;;
|
||||
*.xcassets)
|
||||
ABSOLUTE_XCASSET_FILE=$(realpath "$RESOURCE_PATH")
|
||||
XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE")
|
||||
;;
|
||||
*)
|
||||
echo "$RESOURCE_PATH"
|
||||
echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then
|
||||
mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
fi
|
||||
rm -f "$RESOURCES_TO_COPY"
|
||||
|
||||
if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ]
|
||||
then
|
||||
# Find all other xcassets (this unfortunately includes those of path pods and other targets).
|
||||
OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d)
|
||||
while read line; do
|
||||
if [[ $line != "`realpath $PODS_ROOT`*" ]]; then
|
||||
XCASSET_FILES+=("$line")
|
||||
fi
|
||||
done <<<"$OTHER_XCASSETS"
|
||||
|
||||
printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
fi
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
FOUNDATION_EXPORT double Pods_SwiftChess_ExampleVersionNumber;
|
||||
FOUNDATION_EXPORT const unsigned char Pods_SwiftChess_ExampleVersionString[];
|
||||
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
framework module Pods_SwiftChess_Example {
|
||||
umbrella header "Pods-SwiftChess_Example-umbrella.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
# Acknowledgements
|
||||
This application makes use of the following third party libraries:
|
||||
|
||||
## SwiftChess
|
||||
|
||||
Copyright (c) 2016 Steve Barnegren <steve.barnegren@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
Generated by CocoaPods - https://cocoapods.org
|
||||
Example/Pods/Target Support Files/Pods-SwiftChess_Tests/Pods-SwiftChess_Tests-acknowledgements.plist
Generated
-56
@@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>PreferenceSpecifiers</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>This application makes use of the following third party libraries:</string>
|
||||
<key>Title</key>
|
||||
<string>Acknowledgements</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Copyright (c) 2016 Steve Barnegren <steve.barnegren@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>SwiftChess</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Generated by CocoaPods - https://cocoapods.org</string>
|
||||
<key>Title</key>
|
||||
<string></string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>StringsTable</key>
|
||||
<string>Acknowledgements</string>
|
||||
<key>Title</key>
|
||||
<string>Acknowledgements</string>
|
||||
</dict>
|
||||
</plist>
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
@interface PodsDummy_Pods_SwiftChess_Tests : NSObject
|
||||
@end
|
||||
@implementation PodsDummy_Pods_SwiftChess_Tests
|
||||
@end
|
||||
Generated
-91
@@ -1,91 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
|
||||
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
|
||||
|
||||
install_framework()
|
||||
{
|
||||
if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
|
||||
local source="${BUILT_PRODUCTS_DIR}/$1"
|
||||
elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
|
||||
local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
|
||||
elif [ -r "$1" ]; then
|
||||
local source="$1"
|
||||
fi
|
||||
|
||||
local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
|
||||
if [ -L "${source}" ]; then
|
||||
echo "Symlinked..."
|
||||
source="$(readlink "${source}")"
|
||||
fi
|
||||
|
||||
# use filter instead of exclude so missing patterns dont' throw errors
|
||||
echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
|
||||
rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"
|
||||
|
||||
local basename
|
||||
basename="$(basename -s .framework "$1")"
|
||||
binary="${destination}/${basename}.framework/${basename}"
|
||||
if ! [ -r "$binary" ]; then
|
||||
binary="${destination}/${basename}"
|
||||
fi
|
||||
|
||||
# Strip invalid architectures so "fat" simulator / device frameworks work on device
|
||||
if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
|
||||
strip_invalid_archs "$binary"
|
||||
fi
|
||||
|
||||
# Resign the code if required by the build settings to avoid unstable apps
|
||||
code_sign_if_enabled "${destination}/$(basename "$1")"
|
||||
|
||||
# Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
|
||||
if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
|
||||
local swift_runtime_libs
|
||||
swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]})
|
||||
for lib in $swift_runtime_libs; do
|
||||
echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
|
||||
rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
|
||||
code_sign_if_enabled "${destination}/${lib}"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Signs a framework with the provided identity
|
||||
code_sign_if_enabled() {
|
||||
if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then
|
||||
# Use the current code_sign_identitiy
|
||||
echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
|
||||
echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements \"$1\""
|
||||
/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Strip invalid architectures
|
||||
strip_invalid_archs() {
|
||||
binary="$1"
|
||||
# Get architectures for current file
|
||||
archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)"
|
||||
stripped=""
|
||||
for arch in $archs; do
|
||||
if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then
|
||||
# Strip non-valid architectures in-place
|
||||
lipo -remove "$arch" -output "$binary" "$binary" || exit 1
|
||||
stripped="$stripped $arch"
|
||||
fi
|
||||
done
|
||||
if [[ "$stripped" ]]; then
|
||||
echo "Stripped $binary of architectures:$stripped"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
if [[ "$CONFIGURATION" == "Debug" ]]; then
|
||||
install_framework "$BUILT_PRODUCTS_DIR/SwiftChess/SwiftChess.framework"
|
||||
fi
|
||||
if [[ "$CONFIGURATION" == "Release" ]]; then
|
||||
install_framework "$BUILT_PRODUCTS_DIR/SwiftChess/SwiftChess.framework"
|
||||
fi
|
||||
Generated
-102
@@ -1,102 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
|
||||
RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt
|
||||
> "$RESOURCES_TO_COPY"
|
||||
|
||||
XCASSET_FILES=()
|
||||
|
||||
case "${TARGETED_DEVICE_FAMILY}" in
|
||||
1,2)
|
||||
TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone"
|
||||
;;
|
||||
1)
|
||||
TARGET_DEVICE_ARGS="--target-device iphone"
|
||||
;;
|
||||
2)
|
||||
TARGET_DEVICE_ARGS="--target-device ipad"
|
||||
;;
|
||||
*)
|
||||
TARGET_DEVICE_ARGS="--target-device mac"
|
||||
;;
|
||||
esac
|
||||
|
||||
realpath() {
|
||||
DIRECTORY="$(cd "${1%/*}" && pwd)"
|
||||
FILENAME="${1##*/}"
|
||||
echo "$DIRECTORY/$FILENAME"
|
||||
}
|
||||
|
||||
install_resource()
|
||||
{
|
||||
if [[ "$1" = /* ]] ; then
|
||||
RESOURCE_PATH="$1"
|
||||
else
|
||||
RESOURCE_PATH="${PODS_ROOT}/$1"
|
||||
fi
|
||||
if [[ ! -e "$RESOURCE_PATH" ]] ; then
|
||||
cat << EOM
|
||||
error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script.
|
||||
EOM
|
||||
exit 1
|
||||
fi
|
||||
case $RESOURCE_PATH in
|
||||
*.storyboard)
|
||||
echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}"
|
||||
ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS}
|
||||
;;
|
||||
*.xib)
|
||||
echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}"
|
||||
ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS}
|
||||
;;
|
||||
*.framework)
|
||||
echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
echo "rsync -av $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
rsync -av "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
;;
|
||||
*.xcdatamodel)
|
||||
echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\""
|
||||
xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom"
|
||||
;;
|
||||
*.xcdatamodeld)
|
||||
echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\""
|
||||
xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd"
|
||||
;;
|
||||
*.xcmappingmodel)
|
||||
echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\""
|
||||
xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm"
|
||||
;;
|
||||
*.xcassets)
|
||||
ABSOLUTE_XCASSET_FILE=$(realpath "$RESOURCE_PATH")
|
||||
XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE")
|
||||
;;
|
||||
*)
|
||||
echo "$RESOURCE_PATH"
|
||||
echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then
|
||||
mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
fi
|
||||
rm -f "$RESOURCES_TO_COPY"
|
||||
|
||||
if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ]
|
||||
then
|
||||
# Find all other xcassets (this unfortunately includes those of path pods and other targets).
|
||||
OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d)
|
||||
while read line; do
|
||||
if [[ $line != "`realpath $PODS_ROOT`*" ]]; then
|
||||
XCASSET_FILES+=("$line")
|
||||
fi
|
||||
done <<<"$OTHER_XCASSETS"
|
||||
|
||||
printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
fi
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
FOUNDATION_EXPORT double Pods_SwiftChess_TestsVersionNumber;
|
||||
FOUNDATION_EXPORT const unsigned char Pods_SwiftChess_TestsVersionString[];
|
||||
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
framework module Pods_SwiftChess_Tests {
|
||||
umbrella header "Pods-SwiftChess_Tests-umbrella.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,5 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
@interface PodsDummy_SwiftChess : NSObject
|
||||
@end
|
||||
@implementation PodsDummy_SwiftChess
|
||||
@end
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef __OBJC__
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
FOUNDATION_EXPORT double SwiftChessVersionNumber;
|
||||
FOUNDATION_EXPORT const unsigned char SwiftChessVersionString[];
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
framework module SwiftChess {
|
||||
umbrella header "SwiftChess-umbrella.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/SwiftChess
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public"
|
||||
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
|
||||
PODS_BUILD_DIR = $BUILD_DIR
|
||||
PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
|
||||
SKIP_INSTALL = YES
|
||||
@@ -13,34 +13,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
func application(_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
protocol BoardViewDelegate {
|
||||
protocol BoardViewDelegate: class {
|
||||
func touchedSquareAtIndex(_ boardView: BoardView, index: Int)
|
||||
}
|
||||
|
||||
class BoardView: UIView {
|
||||
|
||||
// MARK: - Properties
|
||||
internal var delegate: BoardViewDelegate?
|
||||
internal weak var delegate: BoardViewDelegate?
|
||||
|
||||
// MARK: - init
|
||||
|
||||
@@ -29,7 +29,7 @@ class BoardView: UIView {
|
||||
self.setupBoardView()
|
||||
}
|
||||
|
||||
func setupBoardView(){
|
||||
func setupBoardView() {
|
||||
layer.borderColor = UIColor.black.cgColor
|
||||
layer.borderWidth = 1
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class BoardView: UIView {
|
||||
|
||||
}
|
||||
|
||||
func boardIndexForLocation(_ location: CGPoint) -> Int{
|
||||
func boardIndexForLocation(_ location: CGPoint) -> Int {
|
||||
|
||||
// Flip y (0 at bottom)
|
||||
var location = location
|
||||
@@ -110,5 +110,4 @@ class BoardView: UIView {
|
||||
return gridX + (gridY*8)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2016 CocoaPods. All rights reserved.
|
||||
//
|
||||
|
||||
//swiftlint:disable file_length
|
||||
|
||||
import UIKit
|
||||
import SwiftChess
|
||||
|
||||
@@ -21,7 +23,7 @@ class GameViewController: UIViewController {
|
||||
var pieceViews = [PieceView]()
|
||||
var game: Game!
|
||||
var selectedIndex: Int? {
|
||||
didSet{
|
||||
didSet {
|
||||
updatePieceViewSelectedStates()
|
||||
}
|
||||
}
|
||||
@@ -32,12 +34,13 @@ class GameViewController: UIViewController {
|
||||
|
||||
// MARK: - Creation
|
||||
|
||||
class func gameViewController(game: Game) -> GameViewController{
|
||||
class func gameViewController(game: Game) -> GameViewController {
|
||||
|
||||
let storyboard = UIStoryboard(name: "Main", bundle: nil)
|
||||
let className = "GameViewController"
|
||||
let gameViewController: GameViewController = storyboard.instantiateViewController(withIdentifier: className) as! GameViewController
|
||||
gameViewController.game = game;
|
||||
let gameViewController: GameViewController =
|
||||
storyboard.instantiateViewController(withIdentifier: className) as! GameViewController
|
||||
gameViewController.game = game
|
||||
return gameViewController
|
||||
}
|
||||
|
||||
@@ -117,15 +120,7 @@ class GameViewController: UIViewController {
|
||||
}
|
||||
|
||||
func pieceViewWithTag(_ tag: Int) -> PieceView? {
|
||||
|
||||
for pieceView in pieceViews {
|
||||
|
||||
if pieceView.piece.tag == tag {
|
||||
return pieceView
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
return pieceViews.first { $0.piece.tag == tag }
|
||||
}
|
||||
|
||||
// MARK: - Layout
|
||||
@@ -180,39 +175,35 @@ class GameViewController: UIViewController {
|
||||
let player = game.currentPlayer
|
||||
|
||||
var isHuman = true
|
||||
if let _ = player as? AIPlayer {
|
||||
if player is AIPlayer {
|
||||
isHuman = false
|
||||
}
|
||||
|
||||
// White king side button
|
||||
if isHuman && player?.color == .white && game.board.canColorCastle(color: .white, side: .kingSide){
|
||||
if isHuman && player?.color == .white && game.board.canColorCastle(color: .white, side: .kingSide) {
|
||||
whiteKingSideCastleButton.isHidden = false
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
whiteKingSideCastleButton.isHidden = true
|
||||
}
|
||||
|
||||
// White queen side button
|
||||
if isHuman && player?.color == .white && game.board.canColorCastle(color: .white, side: .queenSide){
|
||||
if isHuman && player?.color == .white && game.board.canColorCastle(color: .white, side: .queenSide) {
|
||||
whiteQueenSideCastleButton.isHidden = false
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
whiteQueenSideCastleButton.isHidden = true
|
||||
}
|
||||
|
||||
// Black king side button
|
||||
if isHuman && player?.color == .black && game.board.canColorCastle(color: .black, side: .kingSide){
|
||||
if isHuman && player?.color == .black && game.board.canColorCastle(color: .black, side: .kingSide) {
|
||||
blackKingSideCastleButton.isHidden = false
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
blackKingSideCastleButton.isHidden = true
|
||||
}
|
||||
|
||||
// Black queen side button
|
||||
if isHuman && player?.color == .black && game.board.canColorCastle(color: .black, side: .queenSide){
|
||||
if isHuman && player?.color == .black && game.board.canColorCastle(color: .black, side: .queenSide) {
|
||||
blackQueenSideCastleButton.isHidden = false
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
blackQueenSideCastleButton.isHidden = true
|
||||
}
|
||||
}
|
||||
@@ -220,7 +211,7 @@ class GameViewController: UIViewController {
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func whiteKingSideCastleButtonPressed(sender: UIButton) {
|
||||
print("White king side castle button pressed");
|
||||
print("White king side castle button pressed")
|
||||
|
||||
if let player = game.currentPlayer as? Human {
|
||||
player.performCastleMove(side: .kingSide)
|
||||
@@ -228,7 +219,7 @@ class GameViewController: UIViewController {
|
||||
}
|
||||
|
||||
@IBAction func whiteQueenSideCastleButtonPressed(sender: UIButton) {
|
||||
print("White queen side castle button pressed");
|
||||
print("White queen side castle button pressed")
|
||||
|
||||
if let player = game.currentPlayer as? Human {
|
||||
player.performCastleMove(side: .queenSide)
|
||||
@@ -236,7 +227,7 @@ class GameViewController: UIViewController {
|
||||
}
|
||||
|
||||
@IBAction func blackKingSideCastleButtonPressed(sender: UIButton) {
|
||||
print("Black king side castle button pressed");
|
||||
print("Black king side castle button pressed")
|
||||
|
||||
if let player = game.currentPlayer as? Human {
|
||||
player.performCastleMove(side: .kingSide)
|
||||
@@ -244,7 +235,7 @@ class GameViewController: UIViewController {
|
||||
}
|
||||
|
||||
@IBAction func blackQueenSideCastleButtonPressed(sender: UIButton) {
|
||||
print("Black queen side castle button pressed");
|
||||
print("Black queen side castle button pressed")
|
||||
|
||||
if let player = game.currentPlayer as? Human {
|
||||
player.performCastleMove(side: .queenSide)
|
||||
@@ -262,7 +253,7 @@ extension GameViewController: BoardViewDelegate {
|
||||
|
||||
// Get the player (must be human)
|
||||
guard let player = game.currentPlayer as? Human else {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
let location = BoardLocation(index: index)
|
||||
@@ -290,11 +281,11 @@ extension GameViewController: BoardViewDelegate {
|
||||
} catch Player.MoveError.pieceUnableToMoveToLocation {
|
||||
print("Piece is unable to move to this location")
|
||||
|
||||
} catch Player.MoveError.cannotMoveInToCheck{
|
||||
} catch Player.MoveError.cannotMoveInToCheck {
|
||||
print("Player cannot move in to check")
|
||||
showAlert(title: "😜", message: "Player cannot move in to check")
|
||||
|
||||
} catch Player.MoveError.playerMustMoveOutOfCheck{
|
||||
} catch Player.MoveError.playerMustMoveOutOfCheck {
|
||||
print("Player must move out of check")
|
||||
showAlert(title: "🙃", message: "Player must move out of check")
|
||||
|
||||
@@ -309,7 +300,7 @@ extension GameViewController: BoardViewDelegate {
|
||||
|
||||
}
|
||||
|
||||
// MARK - GameDelegate
|
||||
// MARK: - GameDelegate
|
||||
|
||||
extension GameViewController: GameDelegate {
|
||||
|
||||
@@ -347,8 +338,7 @@ extension GameViewController: GameDelegate {
|
||||
// Fade out and remove
|
||||
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut, animations: {
|
||||
pieceView.alpha = 0
|
||||
}, completion: {
|
||||
(finished: Bool) in
|
||||
}, completion: { (finished: Bool) in
|
||||
self.removePieceView(withTag: piece.tag)
|
||||
})
|
||||
|
||||
@@ -384,10 +374,10 @@ extension GameViewController: GameDelegate {
|
||||
func gameDidChangeCurrentPlayer(game: Game) {
|
||||
|
||||
// Deselect selected piece
|
||||
self.selectedIndex = nil;
|
||||
self.selectedIndex = nil
|
||||
|
||||
// Tell AI to take go
|
||||
if let _ = game.currentPlayer as? AIPlayer {
|
||||
if game.currentPlayer is AIPlayer {
|
||||
perform(#selector(tellAIToTakeGo), with: nil, afterDelay: 1)
|
||||
}
|
||||
|
||||
@@ -395,19 +385,24 @@ extension GameViewController: GameDelegate {
|
||||
updateCastleButtonsVisibility()
|
||||
}
|
||||
|
||||
func tellAIToTakeGo() {
|
||||
@objc func tellAIToTakeGo() {
|
||||
|
||||
if let player = game.currentPlayer as? AIPlayer {
|
||||
activityIndicator.startAnimating();
|
||||
activityIndicator.startAnimating()
|
||||
player.makeMoveAsync()
|
||||
}
|
||||
}
|
||||
|
||||
func promotedTypeForPawn(location: BoardLocation, player: Human, possiblePromotions: [Piece.PieceType], callback: @escaping (Piece.PieceType) -> Void) {
|
||||
func promotedTypeForPawn(location: BoardLocation,
|
||||
player: Human,
|
||||
possiblePromotions: [Piece.PieceType],
|
||||
callback: @escaping (Piece.PieceType) -> Void) {
|
||||
|
||||
boardView.isUserInteractionEnabled = false
|
||||
|
||||
let viewController = PromotionSelectionViewController.promotionSelectionViewController(pawnLocation: location, possibleTypes: possiblePromotions) {
|
||||
let viewController =
|
||||
PromotionSelectionViewController.promotionSelectionViewController(pawnLocation: location,
|
||||
possibleTypes: possiblePromotions) {
|
||||
|
||||
self.promotionSelectionViewController?.view.removeFromSuperview()
|
||||
self.promotionSelectionViewController?.removeFromParentViewController()
|
||||
@@ -421,6 +416,3 @@ extension GameViewController: GameDelegate {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class MenuViewController: UIViewController {
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func playerVsAIButtonPressed(_ sender: UIButton){
|
||||
@IBAction func playerVsAIButtonPressed(_ sender: UIButton) {
|
||||
print("Player vs AI button pressed")
|
||||
|
||||
let whitePlayer = Human(color: .white)
|
||||
@@ -33,7 +33,7 @@ class MenuViewController: UIViewController {
|
||||
startGame(game: game)
|
||||
}
|
||||
|
||||
@IBAction func playerVsPlayerButtonPressed(_ sender: UIButton){
|
||||
@IBAction func playerVsPlayerButtonPressed(_ sender: UIButton) {
|
||||
print("Player vs Player button pressed")
|
||||
|
||||
let whitePlayer = Human(color: .white)
|
||||
@@ -43,7 +43,7 @@ class MenuViewController: UIViewController {
|
||||
startGame(game: game)
|
||||
}
|
||||
|
||||
@IBAction func AIvsAIButtonPressed(_ sender: UIButton){
|
||||
@IBAction func AIvsAIButtonPressed(_ sender: UIButton) {
|
||||
print("AI vs AI button pressed")
|
||||
|
||||
let whitePlayer = AIPlayer(color: .white, configuration: AIConfiguration(difficulty: .hard))
|
||||
@@ -60,4 +60,3 @@ class MenuViewController: UIViewController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import SwiftChess
|
||||
class PieceView: UIView {
|
||||
|
||||
public var piece: Piece {
|
||||
didSet{
|
||||
didSet {
|
||||
update()
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class PieceView: UIView {
|
||||
let imageView = UIImageView()
|
||||
|
||||
var selected = false {
|
||||
didSet{
|
||||
didSet {
|
||||
update()
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,6 @@ class PieceView: UIView {
|
||||
|
||||
backgroundColor = selected ? UIColor.red : UIColor.clear
|
||||
|
||||
|
||||
/*
|
||||
transform = CGAffineTransform.identity
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ class PromotionSelectionViewController: UIViewController {
|
||||
var buttons = [UIButton]()
|
||||
|
||||
// MARK: - Creation
|
||||
public static func promotionSelectionViewController(pawnLocation: BoardLocation, possibleTypes: [Piece.PieceType], callback: @escaping (Piece.PieceType) -> Void) -> PromotionSelectionViewController {
|
||||
public static func promotionSelectionViewController(pawnLocation: BoardLocation,
|
||||
possibleTypes: [Piece.PieceType],
|
||||
callback: @escaping (Piece.PieceType) -> Void)
|
||||
-> PromotionSelectionViewController {
|
||||
|
||||
let viewController = PromotionSelectionViewController()
|
||||
viewController.pawnLocation = pawnLocation
|
||||
@@ -67,7 +70,7 @@ class PromotionSelectionViewController: UIViewController {
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
func buttonPressed(sender: UIButton) {
|
||||
@objc func buttonPressed(sender: UIButton) {
|
||||
|
||||
let index = buttons.index(of: sender)!
|
||||
print("Button pressed at index: \(index)")
|
||||
@@ -91,5 +94,4 @@ class PromotionSelectionViewController: UIViewController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2017 CocoaPods. All rights reserved.
|
||||
//
|
||||
|
||||
//swiftlint:disable xctfail_message
|
||||
|
||||
/*
|
||||
|
||||
AI behaviour tests are tests that try to avoid or encourage certain behaviours in the AI.
|
||||
@@ -60,7 +62,7 @@ class AIBehaviourTests: XCTestCase {
|
||||
if endBoardPiece != nil && startBoardPiece != nil {
|
||||
|
||||
if endBoardPiece!.color != startBoardPiece!.color
|
||||
&& endBoardPiece!.type != startBoardPiece!.type{
|
||||
&& endBoardPiece!.type != startBoardPiece!.type {
|
||||
return location
|
||||
}
|
||||
}
|
||||
@@ -77,21 +79,20 @@ class AIBehaviourTests: XCTestCase {
|
||||
|
||||
func test_ScenarioOne_BlackShouldNotGiveAwayBishop() {
|
||||
|
||||
|
||||
// In the following example, the black player can move the bishop at (5,7) to the * location (2,4).
|
||||
// The can look like a good move because the bishop will then threaten the white queen at (3,3).
|
||||
// The white queen will also be threatening the black bishop, but because this is a lower value piece black can think that it is in a more preferrable position.
|
||||
// The white queen will also be threatening the black bishop,
|
||||
// but because this is a lower value piece black can think that it is in a more preferrable position.
|
||||
// In reality, because the black bishop is unprotected, the white queen will take it.
|
||||
|
||||
let board = ASCIIBoard(pieces: "r - b - q b - r" +
|
||||
"p p g - - p p p" +
|
||||
"- - - - - k - -" +
|
||||
"- - * - - - - -" +
|
||||
"- - p Q P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P G - - P P P" +
|
||||
"R K B - - B K R" )
|
||||
|
||||
let board = ASCIIBoard(pieces: "r - b - q b - r" +
|
||||
"p p g - - p p p" +
|
||||
"- - - - - k - -" +
|
||||
"- - * - - - - -" +
|
||||
"- - p Q P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P G - - P P P" +
|
||||
"R K B - - B K R" )
|
||||
|
||||
let location = board .locationOfCharacter("*")
|
||||
|
||||
@@ -120,14 +121,14 @@ class AIBehaviourTests: XCTestCase {
|
||||
|
||||
func testBlackShouldTradePawnForQueen() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "g p - - - - - -" +
|
||||
"p p - - - - - -" +
|
||||
"- - - - p - - -" +
|
||||
"- - - - - Q - -" +
|
||||
"- - - - B - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P - - - - - -" +
|
||||
"G P - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "g p - - - - - -" +
|
||||
"p p - - - - - -" +
|
||||
"- - - - p - - -" +
|
||||
"- - - - - Q - -" +
|
||||
"- - - - B - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P - - - - - -" +
|
||||
"G P - - - - - -" )
|
||||
|
||||
let queenLocation = board.locationOfCharacter("Q")
|
||||
let game = makeGameWithBoard(board: board.board, colorToMove: .black)
|
||||
@@ -144,14 +145,14 @@ class AIBehaviourTests: XCTestCase {
|
||||
|
||||
func testBlackShouldTakeWhiteQueenWithPawn() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - p g" +
|
||||
"- - - b - - p p" +
|
||||
"- - - - q - - -" +
|
||||
"- B p k P p - -" +
|
||||
"- - - P Q - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P - - - - - -" +
|
||||
"G P - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - p g" +
|
||||
"- - - b - - p p" +
|
||||
"- - - - q - - -" +
|
||||
"- B p k P p - -" +
|
||||
"- - - P Q - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P - - - - - -" +
|
||||
"G P - - - - - -" )
|
||||
|
||||
let queenLocation = board.locationOfCharacter("Q")
|
||||
let game = makeGameWithBoard(board: board.board, colorToMove: .black)
|
||||
@@ -166,5 +167,4 @@ class AIBehaviourTests: XCTestCase {
|
||||
XCTAssertEqual(game.board.getPiece(at: queenLocation)?.type, .pawn)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,16 +25,15 @@ class AIConfigurationTests: XCTestCase {
|
||||
|
||||
func testBoardRaterCountPiecesWeightingAffectsRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" +
|
||||
"R K B Q G B K R" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" +
|
||||
"R K B Q G B K R" )
|
||||
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterCountPiecesWeighting = 1
|
||||
let lowValueRater = BoardRaterCountPieces(configuration: lowValueConfig)
|
||||
@@ -52,14 +51,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
|
||||
func testBoardDominanceWeightingAffectsRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- P - - - P P -" +
|
||||
"R K B Q G B K R" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- P - - - P P -" +
|
||||
"R K B Q G B K R" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterBoardDominanceWeighting = 1
|
||||
@@ -78,14 +77,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
|
||||
func testCenterOwnershipWeightingAffectsRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - r g r - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - Q B - - -" +
|
||||
"- - - K P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- P - - - P P -" +
|
||||
"R K B Q G B K R" )
|
||||
let board = ASCIIBoard(pieces: "- - - r g r - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - Q B - - -" +
|
||||
"- - - K P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- P - - - P P -" +
|
||||
"R K B Q G B K R" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterCenterOwnershipWeighting = 1
|
||||
@@ -104,14 +103,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
|
||||
func testCenterDominanceWeightingAffetsRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - r g r - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - Q B - - -" +
|
||||
"- - - K P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- P - - - P P -" +
|
||||
"R K B Q G B K R" )
|
||||
let board = ASCIIBoard(pieces: "- - - r g r - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - Q B - - -" +
|
||||
"- - - K P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- P - - - P P -" +
|
||||
"R K B Q G B K R" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterCenterDominanceWeighting = 1
|
||||
@@ -131,14 +130,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
func testBoardRaterThreatenedPiecesWeightingAffectsRating() {
|
||||
|
||||
// White is threatening the black rook with its bishop and knight
|
||||
let board = ASCIIBoard(pieces: "r - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- K - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - B" )
|
||||
let board = ASCIIBoard(pieces: "r - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- K - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - B" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterThreatenedPiecesWeighting = 1
|
||||
@@ -156,14 +155,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
func testBoardRaterThreatenedPiecesOwnPiecesMultiplierAffectsRating() {
|
||||
|
||||
// White and black rook are threatening each other, so advantage is neutral
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - R" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - R" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterThreatenedPiecesOwnPiecesMultiplier = 1
|
||||
@@ -183,14 +182,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
|
||||
func testPawnProgressionWeightingAffectsRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"p p p p p p p p" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"p p p p p p p p" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterPawnProgressionWeighting = 1
|
||||
@@ -209,14 +208,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
|
||||
func testKingSurroundingPossessionWeightingAffectsRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"- - - P G P - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"- - - P G P - -" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterKingSurroundingPossessionWeighting = 1
|
||||
@@ -236,14 +235,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
func testCheckMateOpportunityWeightingAffectsRating() {
|
||||
|
||||
// White can move Rook at (0,0) to (0,7) to check mate black
|
||||
let board = ASCIIBoard(pieces: "- - - - g p - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"R - - P G P - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g p - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"R - - P G P - -" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterCheckMateOpportunityWeighting = 1
|
||||
@@ -263,14 +262,14 @@ class AIConfigurationTests: XCTestCase {
|
||||
|
||||
func testCenterFourOccupationWeightingAffectsRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - p g p - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - K R - - -" +
|
||||
"- - - Q R - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"- - - P G P - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - p g p - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - K R - - -" +
|
||||
"- - - Q R - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"- - - P G P - -" )
|
||||
|
||||
var lowValueConfig = AIConfiguration()
|
||||
lowValueConfig.boardRaterCenterFourOccupationWeighting = 1
|
||||
@@ -285,5 +284,3 @@ class AIConfigurationTests: XCTestCase {
|
||||
XCTAssertGreaterThan(highValueRating, lowValueRating)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,14 +45,14 @@ class AIPlayerTests: XCTestCase {
|
||||
|
||||
func testKnightCannotPutOwnKingInToCheck() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "r - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - * - - - - -" +
|
||||
"K - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "r - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - * - - - - -" +
|
||||
"K - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - - - - -" )
|
||||
|
||||
let knightLocation = board.locationOfCharacter("K")
|
||||
let testLocation = board.locationOfCharacter("*")
|
||||
@@ -70,14 +70,14 @@ class AIPlayerTests: XCTestCase {
|
||||
|
||||
// This is a complex scenario because it was one that I observed from an actual game
|
||||
|
||||
let board = ASCIIBoard(pieces: "r k - - q b - r" +
|
||||
"p p p g k - - p" +
|
||||
"- - * p b p - -" +
|
||||
"P P - - p - p P" +
|
||||
"- - P - P - - -" +
|
||||
"- B - - Q P - -" +
|
||||
"- B - P K G P -" +
|
||||
"R K - - - - - R" )
|
||||
let board = ASCIIBoard(pieces: "r k - - q b - r" +
|
||||
"p p p g k - - p" +
|
||||
"- - * p b p - -" +
|
||||
"P P - - p - p P" +
|
||||
"- - P - P - - -" +
|
||||
"- B - - Q P - -" +
|
||||
"- B - P K G P -" +
|
||||
"R K - - - - - R" )
|
||||
|
||||
let kingLocation = board.locationOfCharacter("g")
|
||||
let testLocation = board.locationOfCharacter("*")
|
||||
@@ -93,14 +93,14 @@ class AIPlayerTests: XCTestCase {
|
||||
|
||||
func testPawnCannotPutOwnKingInToCheck() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - * - - - -" +
|
||||
"G - - P - - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - * - - - -" +
|
||||
"G - - P - - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let pawnLocation = board.locationOfCharacter("P")
|
||||
let testLocation = board.locationOfCharacter("*")
|
||||
@@ -117,14 +117,14 @@ class AIPlayerTests: XCTestCase {
|
||||
|
||||
func testQueenCannotPutOwnKingInToCheck() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - * - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - Q - - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - * - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - Q - - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let queenLocation = board.locationOfCharacter("Q")
|
||||
let testLocation = board.locationOfCharacter("*")
|
||||
@@ -140,14 +140,14 @@ class AIPlayerTests: XCTestCase {
|
||||
|
||||
func testRookCannotPutOwnKingInToCheck() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - * - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - R - - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - * - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - R - - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rookLocation = board.locationOfCharacter("R")
|
||||
let testLocation = board.locationOfCharacter("*")
|
||||
@@ -163,14 +163,14 @@ class AIPlayerTests: XCTestCase {
|
||||
|
||||
func testBishopCannotPutOwnKingInToCheck() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - *" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - B - - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - *" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - B - - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let bishopLocation = board.locationOfCharacter("B")
|
||||
let testLocation = board.locationOfCharacter("*")
|
||||
@@ -183,10 +183,4 @@ class AIPlayerTests: XCTestCase {
|
||||
|
||||
XCTAssertFalse(player.canAIMovePiece(fromLocation: bishopLocation, toLocation: testLocation))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2017 CocoaPods. All rights reserved.
|
||||
//
|
||||
|
||||
//swiftlint:disable function_body_length
|
||||
|
||||
import XCTest
|
||||
@testable import SwiftChess
|
||||
|
||||
@@ -95,10 +97,9 @@ class BoardLocationTests: XCTestCase {
|
||||
(BoardLocation.GridPosition.e8, 60),
|
||||
(BoardLocation.GridPosition.f8, 61),
|
||||
(BoardLocation.GridPosition.g8, 62),
|
||||
(BoardLocation.GridPosition.h8, 63),
|
||||
(BoardLocation.GridPosition.h8, 63)
|
||||
]
|
||||
|
||||
|
||||
for (grid, index) in testCases {
|
||||
XCTAssertEqual(BoardLocation(gridPosition: grid).index, index)
|
||||
XCTAssertEqual(BoardLocation(index: index).gridPosition, grid)
|
||||
@@ -108,14 +109,15 @@ class BoardLocationTests: XCTestCase {
|
||||
|
||||
func testMoveLocationsForColorReturnsCorrectLocations() {
|
||||
|
||||
class FakeOpening : Opening {
|
||||
override func moveGridPositions() -> [(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
class FakeOpening: Opening {
|
||||
override func moveGridPositions()
|
||||
-> [(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
let moves: [(BoardLocation.GridPosition, BoardLocation.GridPosition)] = [
|
||||
(.e2, .e4), // white moves pawn to e4
|
||||
(.e7, .e5), // black moves pawn to e5
|
||||
(.g1, .f3), // white moves knight to f3
|
||||
(.b8, .c6), // black moves knight to c6
|
||||
(.f1, .b5), // white moves bishop to b5
|
||||
(.f1, .b5) // white moves bishop to b5
|
||||
]
|
||||
return moves
|
||||
}
|
||||
@@ -124,12 +126,12 @@ class BoardLocationTests: XCTestCase {
|
||||
let expectedWhiteLocations: [(fromLocation: BoardLocation, toLocation: BoardLocation)] = [
|
||||
(BoardLocation(gridPosition: .e2), BoardLocation(gridPosition: .e4)),
|
||||
(BoardLocation(gridPosition: .g1), BoardLocation(gridPosition: .f3)),
|
||||
(BoardLocation(gridPosition: .f1), BoardLocation(gridPosition: .b5)),
|
||||
(BoardLocation(gridPosition: .f1), BoardLocation(gridPosition: .b5))
|
||||
]
|
||||
|
||||
let expectedBlackLocations: [(fromLocation: BoardLocation, toLocation: BoardLocation)] = [
|
||||
(BoardLocation(gridPosition: .e7), BoardLocation(gridPosition: .e5)),
|
||||
(BoardLocation(gridPosition: .b8), BoardLocation(gridPosition: .c6)),
|
||||
(BoardLocation(gridPosition: .b8), BoardLocation(gridPosition: .c6))
|
||||
]
|
||||
|
||||
let opening = FakeOpening()
|
||||
@@ -160,29 +162,25 @@ class BoardLocationTests: XCTestCase {
|
||||
|
||||
func testIsDarkSquareReturnsExpectedValue() {
|
||||
|
||||
let board = ASCIIBoard(colors: "! * ! * ! * ! *" +
|
||||
"* ! * ! * ! * !" +
|
||||
"! * ! * ! * ! *" +
|
||||
"* ! * ! * ! * !" +
|
||||
"! * ! * ! * ! *" +
|
||||
"* ! * ! * ! * !" +
|
||||
"! * ! * ! * ! *" +
|
||||
"* ! * ! * ! * !" )
|
||||
let board = ASCIIBoard(colors: "! * ! * ! * ! *" +
|
||||
"* ! * ! * ! * !" +
|
||||
"! * ! * ! * ! *" +
|
||||
"* ! * ! * ! * !" +
|
||||
"! * ! * ! * ! *" +
|
||||
"* ! * ! * ! * !" +
|
||||
"! * ! * ! * ! *" +
|
||||
"* ! * ! * ! * !" )
|
||||
|
||||
let darkLocatons = board.locationsWithCharacter("*")
|
||||
let lightLocations = board.locationsWithCharacter("!")
|
||||
|
||||
darkLocatons.forEach{
|
||||
darkLocatons.forEach {
|
||||
XCTAssertTrue($0.isDarkSquare, "Expected \($0) to be dark")
|
||||
}
|
||||
|
||||
lightLocations.forEach{
|
||||
lightLocations.forEach {
|
||||
XCTAssertFalse($0.isDarkSquare, "Expected \($0) to be light")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class BoardRaterBoardDominanceTests: XCTestCase {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
|
||||
self.boardRater = BoardRaterBoardDominance(configuration: AIConfiguration(difficulty: .hard));
|
||||
self.boardRater = BoardRaterBoardDominance(configuration: AIConfiguration(difficulty: .hard))
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
@@ -27,24 +27,24 @@ class BoardRaterBoardDominanceTests: XCTestCase {
|
||||
|
||||
func testSingleQueenResultsInHigherValueThanSinglePawn() {
|
||||
|
||||
let queenBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - Q - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let queenRating = boardRater.ratingfor(board: queenBoard.board, color: .white)
|
||||
|
||||
let pawnBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
let queenBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - P - - -" +
|
||||
"- - - - Q - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let queenRating = boardRater.ratingfor(board: queenBoard.board, color: .white)
|
||||
|
||||
let pawnBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let pawnRating = boardRater.ratingfor(board: pawnBoard.board, color: .white)
|
||||
|
||||
XCTAssertGreaterThan(queenRating, pawnRating)
|
||||
@@ -52,24 +52,24 @@ class BoardRaterBoardDominanceTests: XCTestCase {
|
||||
|
||||
func testOwnPieceBlockingPathResultsInLowerValue() {
|
||||
|
||||
let blockedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P - - - - - - -" +
|
||||
"Q P - - - - - -" )
|
||||
let blockedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P - - - - - - -" +
|
||||
"Q P - - - - - -" )
|
||||
let blockedRating = boardRater.ratingfor(board: blockedBoard.board, color: .white)
|
||||
|
||||
let nonBockedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - - -" )
|
||||
let nonBockedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - - -" )
|
||||
let nonBockedRating = boardRater.ratingfor(board: nonBockedBoard.board, color: .white)
|
||||
|
||||
XCTAssertGreaterThan(nonBockedRating, blockedRating)
|
||||
@@ -78,24 +78,24 @@ class BoardRaterBoardDominanceTests: XCTestCase {
|
||||
|
||||
func testOpponantDominanceResultsInLowerValue() {
|
||||
|
||||
let whiteDominantBoard = ASCIIBoard(pieces: "R - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - k" +
|
||||
"- - - - - - - p" +
|
||||
"Q - - - - - - -" )
|
||||
let whiteDominantBoard = ASCIIBoard(pieces: "R - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - k" +
|
||||
"- - - - - - - p" +
|
||||
"Q - - - - - - -" )
|
||||
let whiteRating = boardRater.ratingfor(board: whiteDominantBoard.board, color: .white)
|
||||
|
||||
let blackDominantBoard = ASCIIBoard(pieces: "r - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - K" +
|
||||
"- - - - - - - P" +
|
||||
"q - - - - - - -" )
|
||||
let blackDominantBoard = ASCIIBoard(pieces: "r - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - K" +
|
||||
"- - - - - - - P" +
|
||||
"q - - - - - - -" )
|
||||
let blackRating = boardRater.ratingfor(board: blackDominantBoard.board, color: .white)
|
||||
|
||||
XCTAssertGreaterThan(whiteRating, blackRating)
|
||||
@@ -103,30 +103,26 @@ class BoardRaterBoardDominanceTests: XCTestCase {
|
||||
|
||||
func testQueenInCornerResultsInLowerValueThanQueenInCenter() {
|
||||
|
||||
let queenInCornerBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - - -" )
|
||||
let queenInCornerBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - - -" )
|
||||
let queenInCornerRating = boardRater.ratingfor(board: queenInCornerBoard.board, color: .white)
|
||||
|
||||
let queenInCenterBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - Q - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let queenInCenterBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - Q - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let queenInCenterRating = boardRater.ratingfor(board: queenInCenterBoard.board, color: .white)
|
||||
|
||||
XCTAssertGreaterThan(queenInCenterRating, queenInCornerRating)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,24 +26,24 @@ class BoardRaterCenterDominanceTests: XCTestCase {
|
||||
|
||||
func testPiecesWithCenterVisibilityResultsInHigherValueThanPiecesWithoutCenterVisibility() {
|
||||
|
||||
let centerVisibleBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - Q" +
|
||||
"- - - - - - - R" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let centerVisibleBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - Q" +
|
||||
"- - - - - - - R" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let centerVisibleRating = boardRater.ratingfor(board: centerVisibleBoard.board, color: .white)
|
||||
|
||||
let centerObstructedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - P -" +
|
||||
"- - - - - - - Q" )
|
||||
let centerObstructedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - P -" +
|
||||
"- - - - - - - Q" )
|
||||
let centerObstructedRating = boardRater.ratingfor(board: centerObstructedBoard.board, color: .white)
|
||||
|
||||
XCTAssertGreaterThan(centerVisibleRating, centerObstructedRating)
|
||||
|
||||
@@ -21,7 +21,6 @@ class BoardRaterCenterFourOccupationTests: XCTestCase {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
|
||||
func defaultBoardRater() -> BoardRaterCenterFourOccupation {
|
||||
|
||||
let configuration = AIConfiguration(difficulty: .hard)
|
||||
@@ -31,14 +30,14 @@ class BoardRaterCenterFourOccupationTests: XCTestCase {
|
||||
|
||||
func testNorthEastCenterSquareResultsInHigherRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = defaultBoardRater().ratingfor(board: board.board, color: .white)
|
||||
XCTAssertGreaterThan(rating, 0)
|
||||
@@ -46,14 +45,14 @@ class BoardRaterCenterFourOccupationTests: XCTestCase {
|
||||
|
||||
func testSouthEastCenterSquareResultsInHigherRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = defaultBoardRater().ratingfor(board: board.board, color: .white)
|
||||
XCTAssertGreaterThan(rating, 0)
|
||||
@@ -61,14 +60,14 @@ class BoardRaterCenterFourOccupationTests: XCTestCase {
|
||||
|
||||
func testSouthWestCenterSquareResultsInHigherRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = defaultBoardRater().ratingfor(board: board.board, color: .white)
|
||||
XCTAssertGreaterThan(rating, 0)
|
||||
@@ -76,14 +75,14 @@ class BoardRaterCenterFourOccupationTests: XCTestCase {
|
||||
|
||||
func testNorthWestCenterSquareResultsInHigherRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = defaultBoardRater().ratingfor(board: board.board, color: .white)
|
||||
XCTAssertGreaterThan(rating, 0)
|
||||
@@ -91,33 +90,32 @@ class BoardRaterCenterFourOccupationTests: XCTestCase {
|
||||
|
||||
func testNonCenterSquaresResultInZeroRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "P P P P P P P P" +
|
||||
"P P P P P P P P" +
|
||||
"P P P P P P P P" +
|
||||
"P P P - - P P P" +
|
||||
"P P P - - P P P" +
|
||||
"P P P P P P P P" +
|
||||
"P P P P P P P P" +
|
||||
"P P P P P P P P" )
|
||||
let board = ASCIIBoard(pieces: "P P P P P P P P" +
|
||||
"P P P P P P P P" +
|
||||
"P P P P P P P P" +
|
||||
"P P P - - P P P" +
|
||||
"P P P - - P P P" +
|
||||
"P P P P P P P P" +
|
||||
"P P P P P P P P" +
|
||||
"P P P P P P P P" )
|
||||
|
||||
let rating = defaultBoardRater().ratingfor(board: board.board, color: .white)
|
||||
XCTAssertEqualWithAccuracy(rating, 0, accuracy: 0.01)
|
||||
XCTAssertEqual(rating, 0, accuracy: 0.01)
|
||||
}
|
||||
|
||||
func testOpponentOccupationResultsInNegativeRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - p p - - -" +
|
||||
"- - - p p - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - p p - - -" +
|
||||
"- - - p p - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = defaultBoardRater().ratingfor(board: board.board, color: .white)
|
||||
XCTAssertLessThan(rating, 0)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,29 +26,29 @@ class BoardRaterCenterOwnershipTests: XCTestCase {
|
||||
|
||||
func testCenterReturnsHigherValueThatSide() {
|
||||
|
||||
let centerBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let centerBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - P - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let centerRating = boardRater.ratingfor(board: centerBoard.board, color: .white);
|
||||
let centerRating = boardRater.ratingfor(board: centerBoard.board, color: .white)
|
||||
|
||||
let sideBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - P -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let sideBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - P -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let sideRating = boardRater.ratingfor(board: sideBoard.board, color: .white);
|
||||
let sideRating = boardRater.ratingfor(board: sideBoard.board, color: .white)
|
||||
|
||||
XCTAssertGreaterThan(centerRating, sideRating);
|
||||
XCTAssertGreaterThan(centerRating, sideRating)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,21 +31,21 @@ class BoardRaterCheckMateOpportunityTests: XCTestCase {
|
||||
let blackRating = boardRater.ratingfor(board: board, color: .black)
|
||||
|
||||
let accuracy = Double(0.1)
|
||||
XCTAssertEqualWithAccuracy(whiteRating, 0, accuracy: accuracy)
|
||||
XCTAssertEqualWithAccuracy(blackRating, 0, accuracy: accuracy)
|
||||
XCTAssertEqual(whiteRating, 0, accuracy: accuracy)
|
||||
XCTAssertEqual(blackRating, 0, accuracy: accuracy)
|
||||
}
|
||||
|
||||
func testThatOpponentKingCheckMateOpportunityResultsInPositiveRating() {
|
||||
|
||||
// White can move the rook at (0, 0) to (0, 7) to put black in check mate
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- R - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"R - - - G - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- R - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"R - - - G - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
XCTAssertGreaterThan(rating, 0)
|
||||
@@ -54,14 +54,14 @@ class BoardRaterCheckMateOpportunityTests: XCTestCase {
|
||||
func testThatOwnKingCheckMateOpportunityResultsInNegativeRating() {
|
||||
|
||||
// Black can move the rook at (0, 7) to (0, 0) to put white in check mate
|
||||
let board = ASCIIBoard(pieces: "r - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- r - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let board = ASCIIBoard(pieces: "r - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- r - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
XCTAssertLessThan(rating, 0)
|
||||
@@ -70,14 +70,14 @@ class BoardRaterCheckMateOpportunityTests: XCTestCase {
|
||||
func testThatMultipleCheckMateOpportunitiesResultInHigherRating() {
|
||||
|
||||
// White can move the rook at (0, 0) to (0, 7) to put black in check mate
|
||||
let singleCheckMateBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- R - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"R - - - G - - -" )
|
||||
let singleCheckMateBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- R - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"R - - - G - - -" )
|
||||
|
||||
// White can also move the rook at (7, 0) to (7, 7) to put black in check mate
|
||||
let multipleCheckMateBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
@@ -95,5 +95,4 @@ class BoardRaterCheckMateOpportunityTests: XCTestCase {
|
||||
XCTAssertGreaterThan(multipleRating, singleRating)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class BoardRaterCountPiecesTests: XCTestCase {
|
||||
super.setUp()
|
||||
|
||||
// Initiailise a new board rater for each test
|
||||
boardRater = BoardRaterCountPieces(configuration: AIConfiguration(difficulty: .hard));
|
||||
boardRater = BoardRaterCountPieces(configuration: AIConfiguration(difficulty: .hard))
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
@@ -27,14 +27,14 @@ class BoardRaterCountPiecesTests: XCTestCase {
|
||||
|
||||
func testWhiteWinningResultsInPositiveValue() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" +
|
||||
"R K B Q G B K R" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" +
|
||||
"R K B Q G B K R" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
XCTAssert(rating > 0, "Expected rating to be positive")
|
||||
@@ -42,14 +42,14 @@ class BoardRaterCountPiecesTests: XCTestCase {
|
||||
|
||||
func testWhiteLosingResultsInNegativeValue() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "r k b q g b k r" +
|
||||
"p p p p p p p p" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "r k b q g b k r" +
|
||||
"p p p p p p p p" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
XCTAssert(rating < 0, "Expected rating to be negative")
|
||||
@@ -57,24 +57,24 @@ class BoardRaterCountPiecesTests: XCTestCase {
|
||||
|
||||
func testGreaterNumberOfPiecesResultsInHigherValue() {
|
||||
|
||||
let fewerPiecesBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" )
|
||||
|
||||
let morePiecesBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
let fewerPiecesBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" +
|
||||
"P P P P P P P P" )
|
||||
|
||||
let morePiecesBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P P P P P P" +
|
||||
"P P P P P P P P" )
|
||||
|
||||
let fewerPiecesRating = boardRater.ratingfor(board: fewerPiecesBoard.board, color: .white)
|
||||
let morePiecesRating = boardRater.ratingfor(board: morePiecesBoard.board, color: .white)
|
||||
XCTAssert(morePiecesRating > fewerPiecesRating, "Expected more pieces to produce higher rating")
|
||||
@@ -82,16 +82,16 @@ class BoardRaterCountPiecesTests: XCTestCase {
|
||||
|
||||
func testHigherValuePiecesResultsInHigherRating() {
|
||||
|
||||
let lowerValuePiecesBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P - - - - -" )
|
||||
let lowerValuePiecesBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"P P P - - - - -" )
|
||||
|
||||
let higherValuePiecesBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
let higherValuePiecesBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
@@ -102,21 +102,19 @@ class BoardRaterCountPiecesTests: XCTestCase {
|
||||
|
||||
let lowerValuePiecesRating = boardRater.ratingfor(board: lowerValuePiecesBoard.board, color: .white)
|
||||
let higherValuePiecesRating = boardRater.ratingfor(board: higherValuePiecesBoard.board, color: .white)
|
||||
XCTAssert(higherValuePiecesRating > lowerValuePiecesRating, "Expected higher value pieces to produce higher rating")
|
||||
XCTAssert(higherValuePiecesRating > lowerValuePiecesRating,
|
||||
"Expected higher value pieces to produce higher rating")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// MARK - Perfomance
|
||||
// MARK: - Perfomance
|
||||
|
||||
func testRatingPerformance() {
|
||||
|
||||
let board = Board(state: .newGame)
|
||||
|
||||
self.measure {
|
||||
for _ in 0..<1000{
|
||||
let _ = self.boardRater.ratingfor(board: board, color: .white)
|
||||
for _ in 0..<1000 {
|
||||
_ = self.boardRater.ratingfor(board: board, color: .white)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
// Copyright © 2016 CocoaPods. All rights reserved.
|
||||
//
|
||||
|
||||
// swiftlint:disable type_body_length
|
||||
// swiftlint:disable file_length
|
||||
|
||||
import XCTest
|
||||
@testable import SwiftChess
|
||||
|
||||
@@ -32,164 +35,154 @@ class BoardRaterKingSurroundingPossessionTests: XCTestCase {
|
||||
let surroundingLocations = self.boardRater.locationsSurroundingKing(color: color, board: board.board)
|
||||
|
||||
XCTAssertEqual(indexes.count, surroundingLocations.count,
|
||||
"Expected counts to be the same (\(indexes.count) indexes \(surroundingLocations.count) surrounding locations).")
|
||||
|
||||
"Expected same: (\(indexes.count) indexes \(surroundingLocations.count) surrounding locations).")
|
||||
|
||||
for index in indexes {
|
||||
|
||||
let location = BoardLocation(index: index)
|
||||
var foundLocation = false
|
||||
|
||||
for surroundingLocation in surroundingLocations {
|
||||
|
||||
if surroundingLocation == location {
|
||||
foundLocation = true
|
||||
}
|
||||
}
|
||||
let foundLocation = surroundingLocations.contains { $0 == location }
|
||||
|
||||
XCTAssertTrue(foundLocation, "Expected location x: \(location.x) y: \(location.y) to be returned")
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
func testWhiteKingSurroundingSpacesReturnsCorrectIndexesInCenter() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - * * * - - -" +
|
||||
"- - * G * - - -" +
|
||||
"- - * * * - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - * * * - - -" +
|
||||
"- - * G * - - -" +
|
||||
"- - * * * - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .white, board: board)
|
||||
}
|
||||
|
||||
func testWhiteKingSurroundingSpacesReturnsCorrectIndexesInBottomLeft() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"* * - - - - - -" +
|
||||
"G * - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"* * - - - - - -" +
|
||||
"G * - - - - - -" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .white, board: board)
|
||||
}
|
||||
|
||||
func testWhiteKingSurroundingSpacesReturnsCorrectIndexesInBottomRight() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - * *" +
|
||||
"- - - - - - * G" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - * *" +
|
||||
"- - - - - - * G" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .white, board: board)
|
||||
}
|
||||
|
||||
func testWhiteKingSurroundingSpacesReturnsCorrectIndexesInTopLeft() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "G * - - - - - -" +
|
||||
"* * - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "G * - - - - - -" +
|
||||
"* * - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .white, board: board)
|
||||
}
|
||||
|
||||
func testWhiteKingSurroundingSpacesReturnsCorrectIndexesInTopRight() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - * G" +
|
||||
"- - - - - - * *" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - * G" +
|
||||
"- - - - - - * *" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .white, board: board)
|
||||
}
|
||||
|
||||
func testBlackKingSurroundingSpacesReturnsCorrectIndexesInCenter() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - * * * - - -" +
|
||||
"- - * g * - - -" +
|
||||
"- - * * * - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - * * * - - -" +
|
||||
"- - * g * - - -" +
|
||||
"- - * * * - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .black, board: board)
|
||||
}
|
||||
|
||||
func testBlackKingSurroundingSpacesReturnsCorrectIndexesInBottomLeft() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"* * - - - - - -" +
|
||||
"g * - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"* * - - - - - -" +
|
||||
"g * - - - - - -" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .black, board: board)
|
||||
}
|
||||
|
||||
func testBlackKingSurroundingSpacesReturnsCorrectIndexesInBottomRight() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - * *" +
|
||||
"- - - - - - * g" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - * *" +
|
||||
"- - - - - - * g" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .black, board: board)
|
||||
}
|
||||
|
||||
func testBlackKingSurroundingSpacesReturnsCorrectIndexesInTopLeft() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "g * - - - - - -" +
|
||||
"* * - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "g * - - - - - -" +
|
||||
"* * - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .black, board: board)
|
||||
}
|
||||
|
||||
func testBlackKingSurroundingSpacesReturnsCorrectIndexesInTopRight() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - * g" +
|
||||
"- - - - - - * *" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - * g" +
|
||||
"- - - - - - * *" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
assertSurroundingSpacesAreCorrect(color: .black, board: board)
|
||||
}
|
||||
@@ -207,14 +200,14 @@ class BoardRaterKingSurroundingPossessionTests: XCTestCase {
|
||||
"r - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let highRatingBoard = ASCIIBoard(pieces:"- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let highRatingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let lowRating = boardRater.ratingfor(board: lowRatingBoard.board, color: .white)
|
||||
let highRating = boardRater.ratingfor(board: highRatingBoard.board, color: .white)
|
||||
@@ -233,14 +226,14 @@ class BoardRaterKingSurroundingPossessionTests: XCTestCase {
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let highRatingBoard = ASCIIBoard(pieces:"- - - - - - - -" +
|
||||
"- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"R - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let highRatingBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"R - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let lowRating = boardRater.ratingfor(board: lowRatingBoard.board, color: .white)
|
||||
let highRating = boardRater.ratingfor(board: highRatingBoard.board, color: .white)
|
||||
@@ -259,14 +252,14 @@ class BoardRaterKingSurroundingPossessionTests: XCTestCase {
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let highRatingBoard = ASCIIBoard(pieces:"- - - - g - - -" +
|
||||
"R - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let highRatingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"R - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let lowRating = boardRater.ratingfor(board: lowRatingBoard.board, color: .white)
|
||||
let highRating = boardRater.ratingfor(board: highRatingBoard.board, color: .white)
|
||||
@@ -285,58 +278,57 @@ class BoardRaterKingSurroundingPossessionTests: XCTestCase {
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let highRatingBoard = ASCIIBoard(pieces:"- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let highRatingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let lowRating = boardRater.ratingfor(board: lowRatingBoard.board, color: .white)
|
||||
let highRating = boardRater.ratingfor(board: highRatingBoard.board, color: .white)
|
||||
|
||||
XCTAssertGreaterThan(highRating, lowRating)
|
||||
}
|
||||
|
||||
|
||||
func testThatBlackandWhiteRatingsAreTheSame() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - - b" +
|
||||
"R - - - p - - q" +
|
||||
"- k - - G - K -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - - b" +
|
||||
"R - - - p - - q" +
|
||||
"- k - - G - K -" )
|
||||
|
||||
let invertedBoard = ASCIIBoard(pieces: "- - - - G - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"q - - - - - - B" +
|
||||
"r - - - P - - Q" +
|
||||
"- K - - g - k -" )
|
||||
let invertedBoard = ASCIIBoard(pieces: "- - - - G - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"q - - - - - - B" +
|
||||
"r - - - P - - Q" +
|
||||
"- K - - g - k -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
let invertedRating = boardRater.ratingfor(board: invertedBoard.board, color: .black)
|
||||
|
||||
XCTAssertEqualWithAccuracy(rating, invertedRating, accuracy: 0.01)
|
||||
XCTAssertEqual(rating, invertedRating, accuracy: 0.01)
|
||||
}
|
||||
|
||||
func testThatPiecesSurroundingOwnKingResultsInPositiveRatingForWhite() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"- - - P G P - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"- - - P G P - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
XCTAssertGreaterThan(rating, 0)
|
||||
@@ -344,14 +336,14 @@ class BoardRaterKingSurroundingPossessionTests: XCTestCase {
|
||||
|
||||
func testThatPiecesSurroundingOwnKingResultsInPositiveRatingForBlack() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - p g p - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - p g p - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .black)
|
||||
XCTAssertGreaterThan(rating, 0)
|
||||
@@ -359,24 +351,23 @@ class BoardRaterKingSurroundingPossessionTests: XCTestCase {
|
||||
|
||||
func testThatPiecesSurroundingOpponentKingResultsInMoreNegativeRatingForWhite() {
|
||||
|
||||
let openKingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let openKingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let surroundedKingBoard = ASCIIBoard(pieces: "- - - p g p - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let surroundedKingBoard = ASCIIBoard(pieces: "- - - p g p - -" +
|
||||
"- - - p p p - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let openKingRating = boardRater.ratingfor(board: openKingBoard.board, color: .white)
|
||||
let surroundedKingRating = boardRater.ratingfor(board: surroundedKingBoard.board, color: .white)
|
||||
@@ -386,29 +377,27 @@ class BoardRaterKingSurroundingPossessionTests: XCTestCase {
|
||||
|
||||
func testThatPiecesSurroundingOpponentKingResultsInMoreNegativeRatingForBlack() {
|
||||
|
||||
let openKingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
let openKingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - G - - -" )
|
||||
|
||||
let surroundedKingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"- - - P G P - -" )
|
||||
let surroundedKingBoard = ASCIIBoard(pieces: "- - - - g - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - P P P - -" +
|
||||
"- - - P G P - -" )
|
||||
|
||||
|
||||
let openKingRating = boardRater.ratingfor(board: openKingBoard.board, color: .black)
|
||||
let surroundedKingRating = boardRater.ratingfor(board: surroundedKingBoard.board, color: .black)
|
||||
XCTAssertLessThan(surroundedKingRating, openKingRating)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ class BoardRaterPawnProgressionTests: XCTestCase {
|
||||
|
||||
func testProgressedPawnResultsInHigherRatingForWhitePlayer() {
|
||||
|
||||
let progressedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- P - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let progressedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- P - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let lessProgressedBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
@@ -80,69 +80,68 @@ class BoardRaterPawnProgressionTests: XCTestCase {
|
||||
|
||||
func testWhitePawnsOnStartingRowResultInZeroRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- P - P - - P -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- P - P - - P -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
|
||||
XCTAssertEqualWithAccuracy(rating, 0, accuracy: 0.0001)
|
||||
XCTAssertEqual(rating, 0, accuracy: 0.0001)
|
||||
}
|
||||
|
||||
func testBlackPawnsOnStartingRowResultInZeroRating() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- p - p - - p -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- p - p - - p -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .black)
|
||||
|
||||
XCTAssertEqualWithAccuracy(rating, 0, accuracy: 0.0001)
|
||||
XCTAssertEqual(rating, 0, accuracy: 0.0001)
|
||||
}
|
||||
|
||||
func testWhiteAndBlackPawnRelativeSquaresResultInTheSameValue() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - p" +
|
||||
"P - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - p" +
|
||||
"P - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let whiteRating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
let blackRating = boardRater.ratingfor(board: board.board, color: .black)
|
||||
|
||||
XCTAssertEqualWithAccuracy(whiteRating, blackRating, accuracy: 0.0001)
|
||||
XCTAssertEqual(whiteRating, blackRating, accuracy: 0.0001)
|
||||
}
|
||||
|
||||
func testTotalWhiteAndBlackRowsValueAreEqual() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" )
|
||||
let board = ASCIIBoard(pieces: "P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" +
|
||||
"P - - - - - - p" )
|
||||
|
||||
let whiteRating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
let blackRating = boardRater.ratingfor(board: board.board, color: .black)
|
||||
|
||||
XCTAssertEqualWithAccuracy(whiteRating, blackRating, accuracy: 0.0001)
|
||||
XCTAssertEqual(whiteRating, blackRating, accuracy: 0.0001)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2016 CocoaPods. All rights reserved.
|
||||
//
|
||||
|
||||
// swiftlint:disable type_body_length
|
||||
|
||||
import XCTest
|
||||
@testable import SwiftChess
|
||||
|
||||
@@ -27,30 +29,30 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
|
||||
func testBoardRaterThreatededPiecesReturnsNoThreatIfNoOtherPieces() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - Q - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - Q - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
|
||||
XCTAssertEqualWithAccuracy(rating, 0, accuracy: 0.01)
|
||||
XCTAssertEqual(rating, 0, accuracy: 0.01)
|
||||
}
|
||||
|
||||
func testBoardRaterThreatenedPiecesReturnsNegativeValueIfThreatened() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"q - - - - - K -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"q - - - - - K -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
|
||||
@@ -59,121 +61,43 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
|
||||
func testBoardRaterThreatenedPiecesReturnsPositiveValueIfThreateningOpponant() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - k -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - k -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let rating = boardRater.ratingfor(board: board.board, color: .white)
|
||||
|
||||
XCTAssertGreaterThan(rating, 0)
|
||||
}
|
||||
|
||||
func testBoardRaterThreatenedPiecesReturnsHigherThreatValueForHigherValuePieces() {
|
||||
|
||||
/*
|
||||
|
||||
let queenBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"q - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let queenIndex = queenBoard.indexOfCharacter("Q")
|
||||
let queenLocation = BoardLocation(index: queenIndex)
|
||||
let queenRating = boardRater.threatRatingForPiece(at: queenLocation,
|
||||
board: queenBoard.board,
|
||||
color: .white)
|
||||
|
||||
|
||||
|
||||
let knightBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"q - - - - - K -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let knightIndex = knightBoard.indexOfCharacter("K")
|
||||
let knightLocation = BoardLocation(index: knightIndex)
|
||||
let knightRating = boardRater.threatRatingForPiece(at: knightLocation,
|
||||
board: knightBoard.board,
|
||||
color: .white)
|
||||
|
||||
|
||||
XCTAssert(queenRating > knightRating);
|
||||
*/
|
||||
}
|
||||
|
||||
func testBoardRaterThreatenedPiecesReturnsMoreNegativeThreatValueForFavourableTrade() {
|
||||
|
||||
/*
|
||||
|
||||
// Good trade (White rook can be taken by the black queen, but the white pawn will then take the queen)
|
||||
let goodTradeBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - R - - -" +
|
||||
"- - - P - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - q" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
// Bad trade (White rook can be taken by the black pawn, then the white pawn will take the black pawn)
|
||||
let badTradeBoard = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - p - -" +
|
||||
"- - - - R - - -" +
|
||||
"- - - P - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
|
||||
let rookLocation = BoardLocation(index: goodTradeBoard.indexOfCharacter("R"))
|
||||
|
||||
let goodTradeRating = boardRater.threatRatingForPiece(at: rookLocation, board: goodTradeBoard.board, color: .white)
|
||||
let badTradeRating = boardRater.threatRatingForPiece(at: rookLocation, board: badTradeBoard.board, color: .white)
|
||||
|
||||
XCTAssert(goodTradeRating < badTradeRating);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
// MARK - Get protected pieces tests
|
||||
// MARK: - Get protected pieces tests
|
||||
|
||||
func testGetProtectingPiecesReturnsProtectingPieces() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - K - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - R -" +
|
||||
"- - - B - - - -" )
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - K - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - R -" +
|
||||
"- - - B - - - -" )
|
||||
|
||||
let expectedIndexes = [
|
||||
board.indexOfCharacter("K"),
|
||||
board.indexOfCharacter("R"),
|
||||
board.indexOfCharacter("B"),
|
||||
board.indexOfCharacter("B")
|
||||
]
|
||||
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("Q"))
|
||||
let gameBoard = board.board
|
||||
let protectingLocations = boardRater.getPieces(protecting: gameBoard.getPiece(at: queenLocation)!,
|
||||
onBoard: board.board).map{ $0.location }
|
||||
onBoard: board.board).map { $0.location }
|
||||
|
||||
// Check all of the expected locations appeared in the protecting locations array
|
||||
for expectedIndex in expectedIndexes {
|
||||
@@ -198,20 +122,20 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertTrue(wasExpected, "Found unexpected protecting location \(location)");
|
||||
XCTAssertTrue(wasExpected, "Found unexpected protecting location \(location)")
|
||||
}
|
||||
}
|
||||
|
||||
func testGetProtectingPiecesDoesntReturnNonProtectingPiecesOfSameColor() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - K - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"R - - - - - - -" +
|
||||
"- B - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - K - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"R - - - - - - -" +
|
||||
"- B - - - - - -" )
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("Q"))
|
||||
let gameBoard = board.board
|
||||
@@ -225,14 +149,14 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
|
||||
func testGetProtectingPiecesDoesntReturnThreateningPiecesOfOppositeColor() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - k - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - r -" +
|
||||
"- - - b - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - k - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - r -" +
|
||||
"- - - b - - - -" )
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("Q"))
|
||||
let gameBoard = board.board
|
||||
@@ -246,14 +170,14 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
|
||||
func testGetProtectingPiecesDoesntReturnPawnsMovingStraightAhead() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - P -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - P -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("Q"))
|
||||
let gameBoard = board.board
|
||||
@@ -267,14 +191,14 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
|
||||
func testGetProtectingPiecesReturnsPawnsMovingDiagonally() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - P - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - P - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("Q"))
|
||||
let gameBoard = board.board
|
||||
@@ -285,32 +209,30 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
XCTAssertTrue(protectingPieces.count == 1)
|
||||
}
|
||||
|
||||
// MARK - Get threatening pieces tests
|
||||
|
||||
// MARK: - Get threatening pieces tests
|
||||
|
||||
func testGetThreateningPiecesReturnsThreateningPieces() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - k - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - r -" +
|
||||
"- - - b - - - -" )
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - k - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - r -" +
|
||||
"- - - b - - - -" )
|
||||
|
||||
let expectedIndexes = [
|
||||
board.indexOfCharacter("k"),
|
||||
board.indexOfCharacter("r"),
|
||||
board.indexOfCharacter("b"),
|
||||
board.indexOfCharacter("b")
|
||||
]
|
||||
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("Q"))
|
||||
let gameBoard = board.board
|
||||
|
||||
let threateningLocations = boardRater.getPieces(threatening: gameBoard.getPiece(at: queenLocation)!,
|
||||
onBoard: gameBoard).map{ $0.location }
|
||||
onBoard: gameBoard).map { $0.location }
|
||||
|
||||
// Check all of the expected locations appeared in the protecting locations array
|
||||
for expectedIndex in expectedIndexes {
|
||||
@@ -335,20 +257,20 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertTrue(wasExpected, "Found unexpected threatening location \(location)");
|
||||
XCTAssertTrue(wasExpected, "Found unexpected threatening location \(location)")
|
||||
}
|
||||
}
|
||||
|
||||
func testGetThreateningPiecesDoesntReturnNonThreateningPiecesOfOppositeColor() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - k - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - -" +
|
||||
"- b - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - k - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - -" +
|
||||
"- b - - - - - -" )
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("Q"))
|
||||
let gameBoard = board.board
|
||||
@@ -362,14 +284,14 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
|
||||
func testGetThreateningPiecesDoesntReturnProtectingPiecesOfSameColor() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - K - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - R -" +
|
||||
"- - - B - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - K - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - Q -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - R -" +
|
||||
"- - - B - - - -" )
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("Q"))
|
||||
let gameBoard = board.board
|
||||
@@ -383,14 +305,14 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
|
||||
func testGetThreateningPiecesDoesntReturnPawnsMovingStraightAhead() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - q -" +
|
||||
"- - - - - - P -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - q -" +
|
||||
"- - - - - - P -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("q"))
|
||||
let gameBoard = board.board
|
||||
@@ -403,14 +325,14 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
|
||||
func testGetThreateningPiecesReturnsPawnsMovingDiagonally() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - q -" +
|
||||
"- - - - - P - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - q -" +
|
||||
"- - - - - P - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let queenLocation = BoardLocation(index: board.indexOfCharacter("q"))
|
||||
let gameBoard = board.board
|
||||
@@ -421,6 +343,4 @@ class BoardRaterThreatenedPiecesTests: XCTestCase {
|
||||
XCTAssertTrue(threateningPieces.count == 1)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,52 +13,50 @@ extension Board {
|
||||
|
||||
public static func whiteInStaleMateScenario() -> Board {
|
||||
|
||||
return ASCIIBoard(pieces: "- - r - r - - g" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"q - - - - - - -" +
|
||||
"- - - G - - - -" ).board
|
||||
return ASCIIBoard(pieces: "- - r - r - - g" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"q - - - - - - -" +
|
||||
"- - - G - - - -" ).board
|
||||
}
|
||||
|
||||
public static func blackInStaleMateScenario() -> Board {
|
||||
|
||||
return ASCIIBoard(pieces: "- - R - R - - G" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - - -" +
|
||||
"- - - g - - - -" ).board
|
||||
return ASCIIBoard(pieces: "- - R - R - - G" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"Q - - - - - - -" +
|
||||
"- - - g - - - -" ).board
|
||||
}
|
||||
|
||||
public static func whiteInCheckMateScenario() -> Board {
|
||||
|
||||
return ASCIIBoard(pieces: "- p g - - - - K" +
|
||||
"- - - - - P - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - -" +
|
||||
"r - - G - - - -" ).board
|
||||
return ASCIIBoard(pieces: "- p g - - - - K" +
|
||||
"- - - - - P - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"r - - - - - - -" +
|
||||
"r - - G - - - -" ).board
|
||||
}
|
||||
|
||||
public static func blackInCheckMateScenario() -> Board {
|
||||
|
||||
return ASCIIBoard(pieces: "- - - g - - - R" +
|
||||
"- - - - - - - R" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- G - - - - - -" ).board
|
||||
return ASCIIBoard(pieces: "- - - g - - - R" +
|
||||
"- - - - - - - R" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- G - - - - - -" ).board
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+364
-358
File diff suppressed because it is too large
Load Diff
@@ -67,7 +67,7 @@ class GameTests: XCTestCase {
|
||||
try whitePlayer.movePiece(fromLocation: BoardLocation(x: 0, y: 1),
|
||||
toLocation: BoardLocation(x: 0, y: 2))
|
||||
} catch {
|
||||
XCTFail()
|
||||
XCTFail("Expected to be able to move piece")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class GameTests: XCTestCase {
|
||||
try blackPlayer.movePiece(fromLocation: BoardLocation(x: 7, y: 6),
|
||||
toLocation: BoardLocation(x: 7, y: 5))
|
||||
} catch {
|
||||
XCTFail()
|
||||
XCTFail("Expected to be able to move piece")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class OpeningsTests: XCTestCase {
|
||||
print("Testing \(opening)")
|
||||
|
||||
var board = Board(state: .newGame)
|
||||
for (source, target) in opening.moveLocations(){
|
||||
for (source, target) in opening.moveLocations() {
|
||||
|
||||
// Assert that the piece exists
|
||||
guard let piece = board.getPiece(at: source) else {
|
||||
@@ -41,8 +41,7 @@ class OpeningsTests: XCTestCase {
|
||||
// Assert the piece can move
|
||||
if piece.movement.canPieceMove(fromLocation: source, toLocation: target, board: board) {
|
||||
board.movePiece(fromLocation: source, toLocation: target)
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
XCTFail("Cannot move piece from \(source) to \(target)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,6 @@ import XCTest
|
||||
@testable import SwiftChess
|
||||
|
||||
class PerformanceTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
@@ -29,7 +22,7 @@ class PerformanceTests: XCTestCase {
|
||||
let pawnLocation = BoardLocation(x: 0, y: 1)
|
||||
|
||||
guard let pawn = board.getPiece(at: pawnLocation) else {
|
||||
XCTFail()
|
||||
XCTFail("Expected to be able to get piece")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -37,10 +30,10 @@ class PerformanceTests: XCTestCase {
|
||||
|
||||
self.measure {
|
||||
|
||||
BoardLocation.all.forEach{
|
||||
pawn.movement.canPieceMove(fromLocation: pawnLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
BoardLocation.all.forEach {
|
||||
_ = pawn.movement.canPieceMove(fromLocation: pawnLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +53,7 @@ class PerformanceTests: XCTestCase {
|
||||
let board = asciiBoard.board
|
||||
|
||||
guard let queen = board.getPiece(at: queenLocation) else {
|
||||
XCTFail()
|
||||
XCTFail("Expected to be able to get piece")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -68,10 +61,10 @@ class PerformanceTests: XCTestCase {
|
||||
|
||||
self.measure {
|
||||
|
||||
BoardLocation.all.forEach{
|
||||
queen.movement.canPieceMove(fromLocation: queenLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
BoardLocation.all.forEach {
|
||||
_ = queen.movement.canPieceMove(fromLocation: queenLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +84,7 @@ class PerformanceTests: XCTestCase {
|
||||
let board = asciiBoard.board
|
||||
|
||||
guard let king = board.getPiece(at: kingLocation) else {
|
||||
XCTFail()
|
||||
XCTFail("Expected to be able tp get piece")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -99,10 +92,10 @@ class PerformanceTests: XCTestCase {
|
||||
|
||||
self.measure {
|
||||
|
||||
BoardLocation.all.forEach{
|
||||
king.movement.canPieceMove(fromLocation: kingLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
BoardLocation.all.forEach {
|
||||
_ = king.movement.canPieceMove(fromLocation: kingLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,7 +115,7 @@ class PerformanceTests: XCTestCase {
|
||||
let board = asciiBoard.board
|
||||
|
||||
guard let knight = board.getPiece(at: knightLocation) else {
|
||||
XCTFail()
|
||||
XCTFail("Exected to be able to get piece")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -130,10 +123,10 @@ class PerformanceTests: XCTestCase {
|
||||
|
||||
self.measure {
|
||||
|
||||
BoardLocation.all.forEach{
|
||||
knight.movement.canPieceMove(fromLocation: knightLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
BoardLocation.all.forEach {
|
||||
_ = knight.movement.canPieceMove(fromLocation: knightLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +146,7 @@ class PerformanceTests: XCTestCase {
|
||||
let board = asciiBoard.board
|
||||
|
||||
guard let bishop = board.getPiece(at: bishopLocation) else {
|
||||
XCTFail()
|
||||
XCTFail("Expected to be able to get piece")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -161,10 +154,10 @@ class PerformanceTests: XCTestCase {
|
||||
|
||||
self.measure {
|
||||
|
||||
BoardLocation.all.forEach{
|
||||
bishop.movement.canPieceMove(fromLocation: bishopLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
BoardLocation.all.forEach {
|
||||
_ = bishop.movement.canPieceMove(fromLocation: bishopLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,7 +177,7 @@ class PerformanceTests: XCTestCase {
|
||||
let board = asciiBoard.board
|
||||
|
||||
guard let rook = board.getPiece(at: rookLocation) else {
|
||||
XCTFail()
|
||||
XCTFail("Expected to be able to get piece")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -192,10 +185,10 @@ class PerformanceTests: XCTestCase {
|
||||
|
||||
self.measure {
|
||||
|
||||
BoardLocation.all.forEach{
|
||||
rook.movement.canPieceMove(fromLocation: rookLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
BoardLocation.all.forEach {
|
||||
_ = rook.movement.canPieceMove(fromLocation: rookLocation,
|
||||
toLocation: $0,
|
||||
board: board)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,16 +204,15 @@ class PerformanceTests: XCTestCase {
|
||||
"P P P - - P P -" +
|
||||
"R - B Q G B K R" )
|
||||
|
||||
let board = asciiBoard.board;
|
||||
let board = asciiBoard.board
|
||||
|
||||
self.measure {
|
||||
|
||||
BoardLocation.all.forEach{
|
||||
board.canColorMoveAnyPieceToLocation(color: .white, location: $0)
|
||||
board.canColorMoveAnyPieceToLocation(color: .black, location: $0)
|
||||
BoardLocation.all.forEach {
|
||||
_ = board.canColorMoveAnyPieceToLocation(color: .white, location: $0)
|
||||
_ = board.canColorMoveAnyPieceToLocation(color: .black, location: $0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,7 @@ class PieceTests: XCTestCase {
|
||||
for square in board.squares {
|
||||
|
||||
guard let piece = square.piece else {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
XCTAssertFalse(foundTags.contains(piece.tag), "Expected all pieces to have unique tags")
|
||||
|
||||
@@ -33,19 +33,22 @@ class PlayerTests: XCTestCase {
|
||||
func testOccupliesSquareAtLocationReturnsTrueWhenOccupiedByPlayerPiece() {
|
||||
|
||||
let location = BoardLocation(index: 0) // <-- should be occupied by white
|
||||
XCTAssert(game.whitePlayer.occupiesSquareAt(location: location), "Expected square to be occupied by player color")
|
||||
XCTAssert(game.whitePlayer.occupiesSquareAt(location: location),
|
||||
"Expected square to be occupied by player color")
|
||||
}
|
||||
|
||||
func testOccupliesSquareAtLocationReturnsFalseWhenSquareEmpty() {
|
||||
|
||||
let location = BoardLocation(x: 0, y: 2) // <-- should be empty
|
||||
XCTAssert(game.whitePlayer.occupiesSquareAt(location: location) == false, "Expected square to not be occupied by player color")
|
||||
XCTAssert(game.whitePlayer.occupiesSquareAt(location: location) == false,
|
||||
"Expected square to not be occupied by player color")
|
||||
}
|
||||
|
||||
func testOccupliesSquareAtLocationReturnsFalseWhenOccupiedByOppositeColor() {
|
||||
|
||||
let location = BoardLocation(x: 0, y: 7) // <-- should be occupied by black
|
||||
XCTAssert(game.whitePlayer.occupiesSquareAt(location: location) == false, "Expected square to not be occupied by player color")
|
||||
XCTAssert(game.whitePlayer.occupiesSquareAt(location: location) == false,
|
||||
"Expected square to not be occupied by player color")
|
||||
}
|
||||
|
||||
// Piece move tests
|
||||
@@ -69,14 +72,14 @@ class PlayerTests: XCTestCase {
|
||||
|
||||
func testMoveInToCheckErrorIsThrownByMovingQueen() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - * - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - Q - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - * - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - Q - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let queenLocation = board.locationOfCharacter("Q")
|
||||
let targetLocation = board.locationOfCharacter("*")
|
||||
@@ -88,19 +91,20 @@ class PlayerTests: XCTestCase {
|
||||
}
|
||||
|
||||
// Assert that the correct error is thrown
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: queenLocation, toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: queenLocation,
|
||||
toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
}
|
||||
|
||||
func testMoveInToCheckErrorIsThrownByMovingPawn() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - * - - -" +
|
||||
"G - - - P - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - * - - -" +
|
||||
"G - - - P - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let pieceLocation = board.locationOfCharacter("P")
|
||||
let targetLocation = board.locationOfCharacter("*")
|
||||
@@ -112,19 +116,20 @@ class PlayerTests: XCTestCase {
|
||||
}
|
||||
|
||||
// Assert that the correct error is thrown
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation, toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation,
|
||||
toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
}
|
||||
|
||||
func testMoveInToCheckErrorIsThrownByMovingKnight() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - * - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - K - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - * - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - K - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let pieceLocation = board.locationOfCharacter("K")
|
||||
let targetLocation = board.locationOfCharacter("*")
|
||||
@@ -136,19 +141,20 @@ class PlayerTests: XCTestCase {
|
||||
}
|
||||
|
||||
// Assert that the correct error is thrown
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation, toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation,
|
||||
toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
}
|
||||
|
||||
func testMoveInToCheckErrorIsThrownByMovingBishop() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - * - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - B - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - * - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - B - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let pieceLocation = board.locationOfCharacter("B")
|
||||
let targetLocation = board.locationOfCharacter("*")
|
||||
@@ -160,19 +166,20 @@ class PlayerTests: XCTestCase {
|
||||
}
|
||||
|
||||
// Assert that the correct error is thrown
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation, toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation,
|
||||
toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
}
|
||||
|
||||
func testMoveInToCheckErrorIsThrownByMovingRook() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - * - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - R - - r" +
|
||||
"- - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - * - - -" +
|
||||
"- - - - - - - -" +
|
||||
"G - - - R - - r" +
|
||||
"- - - - - - - -" )
|
||||
|
||||
let pieceLocation = board.locationOfCharacter("R")
|
||||
let targetLocation = board.locationOfCharacter("*")
|
||||
@@ -184,19 +191,20 @@ class PlayerTests: XCTestCase {
|
||||
}
|
||||
|
||||
// Assert that the correct error is thrown
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation, toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation,
|
||||
toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
}
|
||||
|
||||
func testMoveInToCheckErrorIsThrownByMovingKing() {
|
||||
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"* - - - - - - r" +
|
||||
"G - - - - - - -" )
|
||||
let board = ASCIIBoard(pieces: "- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"- - - - - - - -" +
|
||||
"* - - - - - - r" +
|
||||
"G - - - - - - -" )
|
||||
|
||||
let pieceLocation = board.locationOfCharacter("G")
|
||||
let targetLocation = board.locationOfCharacter("*")
|
||||
@@ -208,7 +216,8 @@ class PlayerTests: XCTestCase {
|
||||
}
|
||||
|
||||
// Assert that the correct error is thrown
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation, toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
XCTAssertTrue(player.canMovePieceWithError(fromLocation: pieceLocation,
|
||||
toLocation: targetLocation).error == .cannotMoveInToCheck)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,11 +19,4 @@ class Tests: XCTestCase {
|
||||
XCTAssert(true, "Pass")
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measure() {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SwiftChess'
|
||||
s.version = '0.1.0'
|
||||
s.version = '0.2.0'
|
||||
s.summary = 'Chess engine written in Swift'
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
|
||||
# * Finally, don't worry about the indent, CocoaPods strips it!
|
||||
|
||||
s.description = <<-DESC
|
||||
Chess engine written in Swift
|
||||
Chess engine written in Swift, support player vs player, and player vs AI games.
|
||||
DESC
|
||||
|
||||
s.homepage = 'https://github.com/SteveBarnegren/SwiftChess'
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
disabled_rules:
|
||||
- trailing_whitespace
|
||||
- cyclomatic_complexity
|
||||
- nesting
|
||||
- type_name
|
||||
- force_cast
|
||||
- identifier_name
|
||||
@@ -6,16 +6,16 @@
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
// swiftlint:disable for_where
|
||||
import Foundation
|
||||
|
||||
open class AIPlayer : Player {
|
||||
open class AIPlayer: Player {
|
||||
|
||||
let boardRaters: [BoardRater]!
|
||||
public var configuration: AIConfiguration!
|
||||
var openingMoves = [OpeningMove]()
|
||||
|
||||
public init(color: Color, configuration: AIConfiguration){
|
||||
public init(color: Color, configuration: AIConfiguration) {
|
||||
|
||||
self.configuration = configuration
|
||||
|
||||
@@ -58,12 +58,12 @@ open class AIPlayer : Player {
|
||||
var move: Move!
|
||||
|
||||
// Get an opening move
|
||||
if let openingMove = openingMoveForBoard(board){
|
||||
if let openingMove = openingMoveForBoard(board) {
|
||||
//print("Playing opening move")
|
||||
move = openingMove
|
||||
}
|
||||
// Or, get the Highest rated move
|
||||
else{
|
||||
else {
|
||||
move = highestRatedMoveOnBoard(board)
|
||||
}
|
||||
|
||||
@@ -73,10 +73,8 @@ open class AIPlayer : Player {
|
||||
switch move.type {
|
||||
case .singlePiece(let sourceLocation, let targetLocation):
|
||||
operations = game.board.movePiece(fromLocation: sourceLocation, toLocation: targetLocation)
|
||||
//print("Chose move (\(sourceLocation.x),\(sourceLocation.y)) -> (\(targetLocation.x),\(targetLocation.y))");
|
||||
case .castle(let color, let side):
|
||||
operations = game.board.performCastle(color: color, side: side)
|
||||
//print("Chose Castling move");
|
||||
}
|
||||
|
||||
// Promote pawns
|
||||
@@ -86,11 +84,12 @@ open class AIPlayer : Player {
|
||||
game.board = promotePawnsOnBoard(game.board)
|
||||
|
||||
let location = pawnsToPromoteLocations.first!
|
||||
let transformOperation = BoardOperation(type: .transformPiece, piece: game.board.getPiece(at: location)!, location: location)
|
||||
let transformOperation = BoardOperation(type: .transformPiece,
|
||||
piece: game.board.getPiece(at: location)!,
|
||||
location: location)
|
||||
operations.append(transformOperation)
|
||||
}
|
||||
|
||||
|
||||
let strongGame = self.game!
|
||||
DispatchQueue.main.async {
|
||||
strongGame.playerDidMakeMove(player: self, boardOperations: operations)
|
||||
@@ -99,13 +98,11 @@ open class AIPlayer : Player {
|
||||
|
||||
func openingMoveForBoard(_ board: Board) -> Move? {
|
||||
|
||||
let possibleMoves = openingMoves.filter{
|
||||
let possibleMoves = openingMoves.filter {
|
||||
$0.board == board
|
||||
}
|
||||
|
||||
//print("Num opening moves`; \(possibleMoves.count)")
|
||||
|
||||
guard possibleMoves.count > 0 else{
|
||||
guard possibleMoves.count > 0 else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -153,7 +150,7 @@ open class AIPlayer : Player {
|
||||
|
||||
// reduce rating if suicide
|
||||
if resultBoard.canColorMoveAnyPieceToLocation(color: color.opposite(), location: targetLocation) {
|
||||
rating -= (abs(rating) * configuration.suicideMultipler.value);
|
||||
rating -= (abs(rating) * configuration.suicideMultipler.value)
|
||||
}
|
||||
|
||||
let move = Move(type: .singlePiece(sourceLocation: sourceLocation, targetLocation: targetLocation),
|
||||
@@ -185,7 +182,7 @@ open class AIPlayer : Player {
|
||||
|
||||
// If there are no possible moves, we must be in stale mate
|
||||
if possibleMoves.count == 0 {
|
||||
print("There are no possible moves!!!!");
|
||||
print("There are no possible moves!!!!")
|
||||
}
|
||||
|
||||
// Choose move with highest rating
|
||||
@@ -196,13 +193,13 @@ open class AIPlayer : Player {
|
||||
|
||||
if move.rating > highestRating {
|
||||
highestRating = move.rating
|
||||
highestRatedMove = move;
|
||||
highestRatedMove = move
|
||||
}
|
||||
|
||||
//print("rating: \(move.rating)")
|
||||
}
|
||||
|
||||
return highestRatedMove;
|
||||
return highestRatedMove
|
||||
}
|
||||
|
||||
func canAIMovePiece(fromLocation: BoardLocation, toLocation: BoardLocation) -> Bool {
|
||||
@@ -217,10 +214,9 @@ open class AIPlayer : Player {
|
||||
return canMove.result
|
||||
}
|
||||
|
||||
|
||||
func ratingForBoard(_ board: Board) -> Double {
|
||||
|
||||
var rating: Double = 0;
|
||||
var rating: Double = 0
|
||||
|
||||
for boardRater in boardRaters {
|
||||
|
||||
@@ -239,7 +235,6 @@ open class AIPlayer : Player {
|
||||
return rating
|
||||
}
|
||||
|
||||
|
||||
func promotePawnsOnBoard(_ board: Board) -> Board {
|
||||
|
||||
let pawnsToPromoteLocations = board.getLocationsOfPromotablePawns(color: color)
|
||||
@@ -252,21 +247,19 @@ open class AIPlayer : Player {
|
||||
|
||||
let location = pawnsToPromoteLocations.first!
|
||||
|
||||
guard let piece = board.getPiece(at: location) else {
|
||||
guard board.getPiece(at: location) != nil else {
|
||||
return board
|
||||
}
|
||||
|
||||
// Get the ratings
|
||||
var bestType = Piece.PieceType.possiblePawnPromotionResultingTypes().first
|
||||
var bestRating = -Double.greatestFiniteMagnitude
|
||||
var highestRating = -Double.greatestFiniteMagnitude
|
||||
var promotedBoard: Board!
|
||||
|
||||
for pieceType in Piece.PieceType.possiblePawnPromotionResultingTypes() {
|
||||
|
||||
var newBoard = board
|
||||
|
||||
guard let piece = newBoard.getPiece(at: location) else {
|
||||
|
||||
guard newBoard.getPiece(at: location) != nil else {
|
||||
return board
|
||||
}
|
||||
|
||||
@@ -275,9 +268,8 @@ open class AIPlayer : Player {
|
||||
|
||||
let rating = ratingForBoard(newBoard)
|
||||
|
||||
if rating > bestRating {
|
||||
bestRating = rating
|
||||
bestType = pieceType
|
||||
if rating > highestRating {
|
||||
highestRating = rating
|
||||
promotedBoard = newBoard
|
||||
}
|
||||
|
||||
@@ -298,7 +290,7 @@ struct Move {
|
||||
let rating: Double
|
||||
}
|
||||
|
||||
// MARK - BoardRater
|
||||
// MARK: - BoardRater
|
||||
|
||||
internal class BoardRater {
|
||||
|
||||
@@ -308,11 +300,7 @@ internal class BoardRater {
|
||||
self.configuration = configuration
|
||||
}
|
||||
|
||||
func ratingfor(board: Board, color: Color) -> Double{
|
||||
func ratingfor(board: Board, color: Color) -> Double {
|
||||
fatalError("Override ratingFor method in subclasses")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,15 +7,14 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftChess
|
||||
|
||||
func transformASCIIBoardInput(_ input: String) -> String{
|
||||
func transformASCIIBoardInput(_ input: String) -> String {
|
||||
|
||||
let boardArt = input.replacingOccurrences(of: " ", with: "")
|
||||
|
||||
var transformedArt = String()
|
||||
|
||||
for y in (0...7).reversed(){
|
||||
for y in (0...7).reversed() {
|
||||
for x in 0...7 {
|
||||
|
||||
let index = y*8 + x
|
||||
@@ -66,12 +65,12 @@ public struct ASCIIBoard {
|
||||
var board = Board(state: .empty)
|
||||
|
||||
// Clear all pieces on the board
|
||||
BoardLocation.all.forEach{
|
||||
BoardLocation.all.forEach {
|
||||
board.removePiece(atLocation: $0)
|
||||
}
|
||||
|
||||
// Setup pieces from ascii art
|
||||
(0..<64).forEach{
|
||||
(0..<64).forEach {
|
||||
let character = boardArt[boardArt.characters.index(boardArt.startIndex, offsetBy: $0)]
|
||||
|
||||
if let piece = pieceFromCharacter(character) {
|
||||
@@ -82,7 +81,6 @@ public struct ASCIIBoard {
|
||||
return board
|
||||
}
|
||||
|
||||
|
||||
func pieceFromCharacter(_ character: Character) -> Piece? {
|
||||
|
||||
var piece: Piece?
|
||||
@@ -119,7 +117,7 @@ public struct ASCIIBoard {
|
||||
return piece
|
||||
}
|
||||
|
||||
public func indexOfCharacter(_ character: Character) -> Int{
|
||||
public func indexOfCharacter(_ character: Character) -> Int {
|
||||
|
||||
var index: Int?
|
||||
|
||||
@@ -137,11 +135,11 @@ public struct ASCIIBoard {
|
||||
return BoardLocation(index: index)
|
||||
}
|
||||
|
||||
public func indexesWithCharacter(_ character: Character) -> [Int]{
|
||||
public func indexesWithCharacter(_ character: Character) -> [Int] {
|
||||
|
||||
var indexes = [Int]()
|
||||
|
||||
(0..<64).forEach{
|
||||
(0..<64).forEach {
|
||||
let aCharacter = artString[artString.characters.index(artString.startIndex, offsetBy: $0)]
|
||||
if character == aCharacter {
|
||||
indexes.append($0)
|
||||
@@ -157,7 +155,7 @@ public struct ASCIIBoard {
|
||||
|
||||
var locations = [BoardLocation]()
|
||||
|
||||
indexes.forEach{
|
||||
indexes.forEach {
|
||||
let location = BoardLocation(index: $0)
|
||||
locations.append(location)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
//
|
||||
//
|
||||
|
||||
// swiftlint:disable file_length
|
||||
// swiftlint:disable type_body_length
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum CastleSide {
|
||||
@@ -15,13 +18,13 @@ public enum CastleSide {
|
||||
|
||||
// MARK: - ****** Square ******
|
||||
|
||||
public struct Square : Equatable {
|
||||
public struct Square: Equatable {
|
||||
|
||||
public var piece: Piece?
|
||||
|
||||
}
|
||||
|
||||
public func ==(lhs: Square, rhs: Square) -> Bool {
|
||||
public func == (lhs: Square, rhs: Square) -> Bool {
|
||||
|
||||
switch (lhs.piece, rhs.piece) {
|
||||
case (.none, .none):
|
||||
@@ -37,7 +40,7 @@ public func ==(lhs: Square, rhs: Square) -> Bool {
|
||||
|
||||
// MARK: - ****** Board ******
|
||||
|
||||
public struct Board : Equatable {
|
||||
public struct Board: Equatable {
|
||||
|
||||
public enum InitialState {
|
||||
case empty
|
||||
@@ -63,7 +66,7 @@ public struct Board : Equatable {
|
||||
|
||||
mutating func setupForNewGame() {
|
||||
|
||||
func setPieceAtIndex(_ piece: Piece, _ index: Int){
|
||||
func setPieceAtIndex(_ piece: Piece, _ index: Int) {
|
||||
setPiece(piece, at: BoardLocation(index: index))
|
||||
}
|
||||
|
||||
@@ -113,7 +116,8 @@ public struct Board : Equatable {
|
||||
squares[location.index].piece = nil
|
||||
}
|
||||
|
||||
@discardableResult internal mutating func movePiece(fromLocation: BoardLocation, toLocation: BoardLocation) -> [BoardOperation] {
|
||||
@discardableResult internal mutating func movePiece(fromLocation: BoardLocation,
|
||||
toLocation: BoardLocation) -> [BoardOperation] {
|
||||
|
||||
if toLocation == fromLocation {
|
||||
return []
|
||||
@@ -134,7 +138,7 @@ public struct Board : Equatable {
|
||||
}
|
||||
|
||||
squares[toLocation.index].piece = self.squares[fromLocation.index].piece
|
||||
squares[toLocation.index].piece?.location = toLocation;
|
||||
squares[toLocation.index].piece?.location = toLocation
|
||||
squares[toLocation.index].piece?.hasMoved = true
|
||||
squares[fromLocation.index].piece = nil
|
||||
|
||||
@@ -150,7 +154,9 @@ public struct Board : Equatable {
|
||||
}
|
||||
|
||||
if enPassentPiece.canBeTakenByEnPassant && enPassentPiece.color == movingPiece.color.opposite() {
|
||||
squares[enPassentLocation.index].piece = nil;
|
||||
squares[enPassentLocation.index].piece = nil
|
||||
let operation = BoardOperation(type: .removePiece, piece: enPassentPiece, location: enPassentLocation)
|
||||
operations.append(operation)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +192,7 @@ public struct Board : Equatable {
|
||||
|
||||
for square in squares {
|
||||
|
||||
guard let piece = square.piece else{
|
||||
guard let piece = square.piece else {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -196,7 +202,8 @@ public struct Board : Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
// We'll implicitly unwrap this, because there should always be a king for each color on the board. If there isn't, it's an error
|
||||
// We'll implicitly unwrap this, because there should always be a king for each color on the board.
|
||||
// If there isn't, it's an error
|
||||
return king!
|
||||
}
|
||||
|
||||
@@ -204,7 +211,7 @@ public struct Board : Equatable {
|
||||
|
||||
for (index, square) in squares.enumerated() {
|
||||
|
||||
guard let piece = square.piece else{
|
||||
guard let piece = square.piece else {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -240,7 +247,7 @@ public struct Board : Equatable {
|
||||
|
||||
for square in squares {
|
||||
|
||||
guard let piece = square.piece else{
|
||||
guard let piece = square.piece else {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -354,8 +361,7 @@ public struct Board : Equatable {
|
||||
|
||||
if !isColorAbleToMove(color: color) && !isColorInCheckMate(color: color) {
|
||||
return true
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -403,7 +409,8 @@ public struct Board : Equatable {
|
||||
continue
|
||||
}
|
||||
|
||||
if piece.movement.canPieceMove(fromLocation: BoardLocation(index: index), toLocation: location, board: self) {
|
||||
if piece.movement.canPieceMove(fromLocation: BoardLocation(index: index),
|
||||
toLocation: location, board: self) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -422,14 +429,14 @@ public struct Board : Equatable {
|
||||
|
||||
public func possibleMoveLocationsForPiece(atLocation location: BoardLocation) -> [BoardLocation] {
|
||||
|
||||
guard let piece = squares[location.index].piece else{
|
||||
guard let piece = squares[location.index].piece else {
|
||||
return []
|
||||
}
|
||||
|
||||
var locations = [BoardLocation]()
|
||||
|
||||
BoardLocation.all.forEach{
|
||||
if piece.movement.canPieceMove(fromLocation: location, toLocation: $0, board: self){
|
||||
BoardLocation.all.forEach {
|
||||
if piece.movement.canPieceMove(fromLocation: location, toLocation: $0, board: self) {
|
||||
locations.append($0)
|
||||
}
|
||||
}
|
||||
@@ -439,7 +446,7 @@ public struct Board : Equatable {
|
||||
|
||||
// MARK: - Castling
|
||||
|
||||
struct CastleMove{
|
||||
struct CastleMove {
|
||||
let yPos: Int
|
||||
let kingStartXPos: Int
|
||||
let rookStartXPos: Int
|
||||
@@ -522,7 +529,9 @@ public struct Board : Equatable {
|
||||
}
|
||||
|
||||
// Check that there are no pieces between the king and the rook
|
||||
for xPos in min(castleMove.kingStartXPos, castleMove.rookStartXPos)..<max(castleMove.kingStartXPos, castleMove.rookStartXPos) {
|
||||
let rStart = min(castleMove.kingStartXPos, castleMove.rookStartXPos)
|
||||
let rEnd = max(castleMove.kingStartXPos, castleMove.rookStartXPos)
|
||||
for xPos in rStart..<rEnd {
|
||||
|
||||
if xPos == castleMove.kingStartXPos || xPos == castleMove.rookStartXPos {
|
||||
continue
|
||||
@@ -530,7 +539,7 @@ public struct Board : Equatable {
|
||||
|
||||
let location = BoardLocation(x: xPos, y: castleMove.yPos)
|
||||
|
||||
if let piece = getPiece(at: location) {
|
||||
if getPiece(at: location) != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -542,7 +551,9 @@ public struct Board : Equatable {
|
||||
}
|
||||
|
||||
// Check that the king will not end up in, or move through check
|
||||
for xPos in min(castleMove.kingEndXPos, castleMove.kingStartXPos)...max(castleMove.kingEndXPos, castleMove.kingStartXPos) {
|
||||
let kStart = min(castleMove.kingEndXPos, castleMove.kingStartXPos)
|
||||
let kEnd = max(castleMove.kingEndXPos, castleMove.kingStartXPos)
|
||||
for xPos in kStart...kEnd {
|
||||
|
||||
if xPos == castleMove.kingStartXPos {
|
||||
continue
|
||||
@@ -561,12 +572,15 @@ public struct Board : Equatable {
|
||||
|
||||
@discardableResult internal mutating func performCastle(color: Color, side: CastleSide) -> [BoardOperation] {
|
||||
|
||||
assert(canColorCastle(color: color, side: side) == true, "\(color) is unable to castle on side \(side). Call canColorCastle(color: side:) first")
|
||||
assert(canColorCastle(color: color, side: side) == true,
|
||||
"\(color) is unable to castle on side \(side). Call canColorCastle(color: side:) first")
|
||||
|
||||
let castleMove = CastleMove(color: color, side: side)
|
||||
|
||||
let moveKingOperations = self.movePiece(fromLocation: castleMove.kingStartLocation, toLocation: castleMove.kingEndLocation)
|
||||
let moveRookOperations = self.movePiece(fromLocation: castleMove.rookStartLocation, toLocation: castleMove.rookEndLocation)
|
||||
let moveKingOperations = self.movePiece(fromLocation: castleMove.kingStartLocation,
|
||||
toLocation: castleMove.kingEndLocation)
|
||||
let moveRookOperations = self.movePiece(fromLocation: castleMove.rookStartLocation,
|
||||
toLocation: castleMove.rookEndLocation)
|
||||
|
||||
return moveKingOperations + moveRookOperations
|
||||
}
|
||||
@@ -576,10 +590,10 @@ public struct Board : Equatable {
|
||||
public func printBoardColors() {
|
||||
printBoard { (square: Square) -> Character? in
|
||||
|
||||
if let piece = square.piece{
|
||||
if let piece = square.piece {
|
||||
return piece.color == .white ? "W" : "B"
|
||||
}
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,9 +602,9 @@ public struct Board : Equatable {
|
||||
|
||||
var character: Character?
|
||||
|
||||
if let piece = square.piece{
|
||||
if let piece = square.piece {
|
||||
|
||||
switch (piece.type){
|
||||
switch piece.type {
|
||||
case .rook:
|
||||
character = "R"
|
||||
case .knight:
|
||||
@@ -606,7 +620,7 @@ public struct Board : Equatable {
|
||||
|
||||
}
|
||||
}
|
||||
return character;
|
||||
return character
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,9 +629,9 @@ public struct Board : Equatable {
|
||||
|
||||
var character: Character?
|
||||
|
||||
if let piece = square.piece{
|
||||
if let piece = square.piece {
|
||||
|
||||
switch (piece.type){
|
||||
switch piece.type {
|
||||
case .rook:
|
||||
character = piece.color == .white ? "R" : "r"
|
||||
case .knight:
|
||||
@@ -633,17 +647,15 @@ public struct Board : Equatable {
|
||||
}
|
||||
|
||||
}
|
||||
return character;
|
||||
return character
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func printBoard( _ squarePrinter: (Square) -> Character? ){
|
||||
func printBoard( _ squarePrinter: (Square) -> Character? ) {
|
||||
|
||||
var printString = String()
|
||||
|
||||
for y in (0...7).reversed(){
|
||||
for y in (0...7).reversed() {
|
||||
for x in 0...7 {
|
||||
|
||||
let index = y*8 + x
|
||||
@@ -658,6 +670,6 @@ public struct Board : Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
public func ==(lhs: Board, rhs: Board) -> Bool {
|
||||
public func == (lhs: Board, rhs: Board) -> Bool {
|
||||
return lhs.squares == rhs.squares
|
||||
}
|
||||
|
||||
@@ -8,17 +8,17 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct BoardLocation : Equatable {
|
||||
public struct BoardLocation: Equatable {
|
||||
|
||||
public enum GridPosition : Int{
|
||||
case a1; case b1; case c1; case d1; case e1; case f1; case g1; case h1;
|
||||
case a2; case b2; case c2; case d2; case e2; case f2; case g2; case h2;
|
||||
case a3; case b3; case c3; case d3; case e3; case f3; case g3; case h3;
|
||||
case a4; case b4; case c4; case d4; case e4; case f4; case g4; case h4;
|
||||
case a5; case b5; case c5; case d5; case e5; case f5; case g5; case h5;
|
||||
case a6; case b6; case c6; case d6; case e6; case f6; case g6; case h6;
|
||||
case a7; case b7; case c7; case d7; case e7; case f7; case g7; case h7;
|
||||
case a8; case b8; case c8; case d8; case e8; case f8; case g8; case h8;
|
||||
public enum GridPosition: Int {
|
||||
case a1; case b1; case c1; case d1; case e1; case f1; case g1; case h1
|
||||
case a2; case b2; case c2; case d2; case e2; case f2; case g2; case h2
|
||||
case a3; case b3; case c3; case d3; case e3; case f3; case g3; case h3
|
||||
case a4; case b4; case c4; case d4; case e4; case f4; case g4; case h4
|
||||
case a5; case b5; case c5; case d5; case e5; case f5; case g5; case h5
|
||||
case a6; case b6; case c6; case d6; case e6; case f6; case g6; case h6
|
||||
case a7; case b7; case c7; case d7; case e7; case f7; case g7; case h7
|
||||
case a8; case b8; case c8; case d8; case e8; case f8; case g8; case h8
|
||||
}
|
||||
|
||||
public var index: Int
|
||||
@@ -28,11 +28,10 @@ public struct BoardLocation : Equatable {
|
||||
|
||||
if let all = allLocationsBacking {
|
||||
return all
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
var locations = [BoardLocation]()
|
||||
|
||||
(0..<64).forEach{
|
||||
(0..<64).forEach {
|
||||
locations.append(BoardLocation(index: $0))
|
||||
}
|
||||
|
||||
@@ -65,7 +64,7 @@ public struct BoardLocation : Equatable {
|
||||
self.index = x + (y*8)
|
||||
}
|
||||
|
||||
public init(gridPosition: GridPosition){
|
||||
public init(gridPosition: GridPosition) {
|
||||
self.index = gridPosition.rawValue
|
||||
}
|
||||
|
||||
@@ -83,9 +82,11 @@ public struct BoardLocation : Equatable {
|
||||
|
||||
func incrementedBy(stride: BoardStride) -> BoardLocation {
|
||||
|
||||
// TODO: for performance, we should probably only check this if we're in debug mode
|
||||
// TODO: Only call this in debug mode to increace performance!
|
||||
if !canIncrementBy(stride: stride) {
|
||||
// swiftlint:disable line_length
|
||||
print("WARNING! BoardLocation is being incremented by a stride that will result in wrapping! call canIncrementBy(stride: BoardStride) first")
|
||||
// swiftlint:enable line_length
|
||||
}
|
||||
|
||||
return BoardLocation(x: x + stride.x,
|
||||
@@ -95,22 +96,22 @@ public struct BoardLocation : Equatable {
|
||||
func canIncrementBy(stride: BoardStride) -> Bool {
|
||||
|
||||
// Check will not wrap to right
|
||||
if x + stride.x > 7 {
|
||||
if x + stride.x > 7 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check will not wrap to left
|
||||
if x + stride.x < 0 {
|
||||
if x + stride.x < 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check will not wrap top
|
||||
if y + stride.y > 7 {
|
||||
if y + stride.y > 7 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check will not wrap bottom
|
||||
if y + stride.y < 0 {
|
||||
if y + stride.y < 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -130,10 +131,10 @@ public struct BoardLocation : Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
public func ==(lhs: BoardLocation, rhs: BoardLocation) -> Bool {
|
||||
public func == (lhs: BoardLocation, rhs: BoardLocation) -> Bool {
|
||||
return lhs.index == rhs.index
|
||||
}
|
||||
|
||||
public func +(left: BoardLocation, right: BoardLocation) -> BoardLocation {
|
||||
public func + (left: BoardLocation, right: BoardLocation) -> BoardLocation {
|
||||
return BoardLocation(index: left.index + right.index)
|
||||
}
|
||||
|
||||
@@ -8,30 +8,30 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class BoardRaterBoardDominance : BoardRater {
|
||||
class BoardRaterBoardDominance: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
let squareValue = Double(1);
|
||||
let squareValue = Double(1)
|
||||
|
||||
var rating = Double(0)
|
||||
|
||||
// Check this color pieces
|
||||
for sourcelocation in BoardLocation.all {
|
||||
|
||||
guard let piece = board.getPiece(at: sourcelocation) else{
|
||||
continue;
|
||||
guard let piece = board.getPiece(at: sourcelocation) else {
|
||||
continue
|
||||
}
|
||||
|
||||
for targetLocation in BoardLocation.all {
|
||||
if piece.movement.canPieceMove(fromLocation: sourcelocation, toLocation: targetLocation, board: board) {
|
||||
rating += (piece.color == color) ? squareValue : -squareValue;
|
||||
rating += (piece.color == color) ? squareValue : -squareValue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return rating * configuration.boardRaterBoardDominanceWeighting.value;
|
||||
return rating * configuration.boardRaterBoardDominanceWeighting.value
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import Foundation
|
||||
Rates the board according to which player's pieces are able to move to the squares at the center of the board
|
||||
*/
|
||||
|
||||
class BoardRaterCenterDominance : BoardRater {
|
||||
class BoardRaterCenterDominance: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
@@ -26,7 +26,11 @@ class BoardRaterCenterDominance : BoardRater {
|
||||
|
||||
for targetLocation in BoardLocation.all {
|
||||
|
||||
if sourceLocation == targetLocation || piece.movement.canPieceMove(fromLocation: sourceLocation, toLocation: targetLocation, board: board) {
|
||||
if sourceLocation == targetLocation ||
|
||||
piece.movement.canPieceMove(fromLocation: sourceLocation,
|
||||
toLocation: targetLocation,
|
||||
board: board) {
|
||||
|
||||
let value = dominanceValueFor(location: targetLocation)
|
||||
rating += (piece.color == color) ? value : -value
|
||||
}
|
||||
@@ -39,7 +43,7 @@ class BoardRaterCenterDominance : BoardRater {
|
||||
|
||||
func dominanceValueFor(location: BoardLocation) -> Double {
|
||||
|
||||
let axisMiddle = 3.5;
|
||||
let axisMiddle = 3.5
|
||||
|
||||
let x = Double(location.x)
|
||||
let y = Double(location.y)
|
||||
@@ -51,5 +55,4 @@ class BoardRaterCenterDominance : BoardRater {
|
||||
return axisMiddle - distance
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,15 +12,14 @@ class BoardRaterCenterFourOccupation: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
let value = Double(1);
|
||||
let value = Double(1)
|
||||
var rating = Double(0)
|
||||
|
||||
BoardLocation(x: 3, y: 3)
|
||||
let locations = [
|
||||
BoardLocation(x: 4, y: 4), // NE
|
||||
BoardLocation(x: 4, y: 3), // SE
|
||||
BoardLocation(x: 3, y: 3), // SW
|
||||
BoardLocation(x: 3, y: 4), // NW
|
||||
BoardLocation(x: 3, y: 4) // NW
|
||||
]
|
||||
|
||||
for location in locations {
|
||||
|
||||
@@ -12,7 +12,7 @@ import Foundation
|
||||
Rates the board according to which player's pieces are occupying the center of the board
|
||||
*/
|
||||
|
||||
class BoardRaterCenterOwnership : BoardRater {
|
||||
class BoardRaterCenterOwnership: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
@@ -35,7 +35,7 @@ class BoardRaterCenterOwnership : BoardRater {
|
||||
|
||||
func dominanceValueFor(location: BoardLocation) -> Double {
|
||||
|
||||
let axisMiddle = 3.5;
|
||||
let axisMiddle = 3.5
|
||||
|
||||
let x = Double(location.x)
|
||||
let y = Double(location.y)
|
||||
|
||||
@@ -14,7 +14,7 @@ import Foundation
|
||||
Iterates over all possible moves, makes them, and checks if the resulting state is check mate
|
||||
*/
|
||||
|
||||
class BoardRaterCheckMateOpportunity : BoardRater {
|
||||
class BoardRaterCheckMateOpportunity: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
@@ -23,7 +23,7 @@ class BoardRaterCheckMateOpportunity : BoardRater {
|
||||
|
||||
for (index, square) in board.squares.enumerated() {
|
||||
|
||||
guard let piece = square.piece else{
|
||||
guard let piece = square.piece else {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -36,10 +36,9 @@ class BoardRaterCheckMateOpportunity : BoardRater {
|
||||
var movedBoard = board
|
||||
movedBoard.movePiece(fromLocation: sourceLocation, toLocation: location)
|
||||
|
||||
if piece.color == color && movedBoard.isColorInCheckMate(color: color.opposite()){
|
||||
if piece.color == color && movedBoard.isColorInCheckMate(color: color.opposite()) {
|
||||
rating += value
|
||||
}
|
||||
else if piece.color == color.opposite() && movedBoard.isColorInCheckMate(color: color){
|
||||
} else if piece.color == color.opposite() && movedBoard.isColorInCheckMate(color: color) {
|
||||
rating -= value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class BoardRaterCountPieces : BoardRater {
|
||||
class BoardRaterCountPieces: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
var rating : Double = 0
|
||||
var rating: Double = 0
|
||||
|
||||
for square in board.squares {
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class BoardRaterKingSurroundingPossession : BoardRater {
|
||||
class BoardRaterKingSurroundingPossession: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
@@ -30,7 +30,7 @@ class BoardRaterKingSurroundingPossession : BoardRater {
|
||||
|
||||
if noKingsBoard.doesColorOccupyLocation(color: color, location: location) {
|
||||
rating += squareValue
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
if noKingsBoard.doesColorOccupyLocation(color: color.opposite(), location: location) {
|
||||
@@ -40,9 +40,7 @@ class BoardRaterKingSurroundingPossession : BoardRater {
|
||||
|
||||
if noKingsBoard.canColorMoveAnyPieceToLocation(color: color, location: location) {
|
||||
rating += squareValue
|
||||
}
|
||||
|
||||
else if noKingsBoard.canColorMoveAnyPieceToLocation(color: color.opposite(), location: location) {
|
||||
} else if noKingsBoard.canColorMoveAnyPieceToLocation(color: color.opposite(), location: location) {
|
||||
rating -= squareValue
|
||||
}
|
||||
|
||||
@@ -52,7 +50,7 @@ class BoardRaterKingSurroundingPossession : BoardRater {
|
||||
|
||||
if noKingsBoard.doesColorOccupyLocation(color: color, location: location) {
|
||||
rating += squareValue
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
if noKingsBoard.doesColorOccupyLocation(color: color.opposite(), location: location) {
|
||||
@@ -62,9 +60,7 @@ class BoardRaterKingSurroundingPossession : BoardRater {
|
||||
|
||||
if noKingsBoard.canColorMoveAnyPieceToLocation(color: color, location: location) {
|
||||
rating += squareValue
|
||||
}
|
||||
|
||||
else if noKingsBoard.canColorMoveAnyPieceToLocation(color: color.opposite(), location: location) {
|
||||
} else if noKingsBoard.canColorMoveAnyPieceToLocation(color: color.opposite(), location: location) {
|
||||
rating -= squareValue
|
||||
}
|
||||
}
|
||||
@@ -77,14 +73,14 @@ class BoardRaterKingSurroundingPossession : BoardRater {
|
||||
let kingLocation = board.getKingLocation(color: color)
|
||||
|
||||
let strides = [
|
||||
BoardStride(x: 0, y: 1), // N
|
||||
BoardStride(x: 1, y: 1), // NE
|
||||
BoardStride(x: 1, y: 0), // E
|
||||
BoardStride(x: 1, y: -1), // SE
|
||||
BoardStride(x: 0, y: -1), // S
|
||||
BoardStride(x: 0, y: 1), // N
|
||||
BoardStride(x: 1, y: 1), // NE
|
||||
BoardStride(x: 1, y: 0), // E
|
||||
BoardStride(x: 1, y: -1), // SE
|
||||
BoardStride(x: 0, y: -1), // S
|
||||
BoardStride(x: -1, y: -1), // SW
|
||||
BoardStride(x: -1, y: 0), // W
|
||||
BoardStride(x: -1, y: 1), // NW
|
||||
BoardStride(x: -1, y: 0), // W
|
||||
BoardStride(x: -1, y: 1) // NW
|
||||
]
|
||||
|
||||
var surroundingLocations = [BoardLocation]()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class BoardRaterPawnProgression : BoardRater {
|
||||
class BoardRaterPawnProgression: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
@@ -38,12 +38,11 @@ class BoardRaterPawnProgression : BoardRater {
|
||||
if color == .white {
|
||||
|
||||
if location.y < 2 {
|
||||
return 0;
|
||||
return 0
|
||||
}
|
||||
|
||||
squaresAdvanced = location.y - 2
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
|
||||
if location.y > 5 {
|
||||
return 0
|
||||
@@ -52,7 +51,7 @@ class BoardRaterPawnProgression : BoardRater {
|
||||
squaresAdvanced = 7 - (location.y + 2)
|
||||
}
|
||||
|
||||
return Double(squaresAdvanced) * configuration.boardRaterPawnProgressionWeighting.value // <- should probably add some sort of curve
|
||||
return Double(squaresAdvanced) * configuration.boardRaterPawnProgressionWeighting.value
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,59 +10,13 @@ import Foundation
|
||||
|
||||
// Tendancy to protect own pieces
|
||||
|
||||
class BoardRaterThreatenedPieces : BoardRater {
|
||||
|
||||
/*
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
var rating = Double(0)
|
||||
|
||||
let allPieces = board.squares.flatMap{
|
||||
$0.piece
|
||||
}
|
||||
|
||||
for piece in allPieces {
|
||||
|
||||
var value = Double(0)
|
||||
|
||||
let threatenedByPieces = getPieces(threatening: piece, onBoard: board)
|
||||
let protectedByPieces = getPieces(protecting: piece, onBoard: board)
|
||||
let isThreatened = threatenedByPieces.count > 0
|
||||
let isProtected = protectedByPieces.count > 0
|
||||
|
||||
switch (isThreatened, isProtected) {
|
||||
case (false, true):
|
||||
value = piece.value()
|
||||
case (true, false):
|
||||
value = -piece.value()
|
||||
case (true, true):
|
||||
let lowestValueThreat = threatenedByPieces.dropFirst().reduce(threatenedByPieces[0].value(), { (value: Double, piece) -> Double in
|
||||
return min(value, piece.value())
|
||||
})
|
||||
|
||||
if lowestValueThreat < piece.value() {
|
||||
value = -piece.value()
|
||||
}
|
||||
case (false, false):
|
||||
break
|
||||
}
|
||||
|
||||
if piece.color == color.opposite() {
|
||||
value = -value
|
||||
}
|
||||
|
||||
rating += value
|
||||
}
|
||||
|
||||
return rating * configuration.boardRaterThreatenedPiecesWeighting
|
||||
}
|
||||
*/
|
||||
class BoardRaterThreatenedPieces: BoardRater {
|
||||
|
||||
override func ratingfor(board: Board, color: Color) -> Double {
|
||||
|
||||
let rating = board.getPieces(color: color)
|
||||
.map{ threatValue(forPiece: $0, onBoard: board) }
|
||||
.reduce(0,+)
|
||||
.map { threatValue(forPiece: $0, onBoard: board) }
|
||||
.reduce(0, +)
|
||||
* configuration.boardRaterThreatenedPiecesWeighting.value
|
||||
|
||||
return rating
|
||||
@@ -100,8 +54,7 @@ class BoardRaterThreatenedPieces : BoardRater {
|
||||
// If it's protected, is it a good trade
|
||||
if isTargetProtected && targetPiece.value() < piece.value() {
|
||||
return 0
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return targetPiece.value()
|
||||
}
|
||||
}
|
||||
@@ -117,15 +70,21 @@ class BoardRaterThreatenedPieces : BoardRater {
|
||||
var alteredBoard = board
|
||||
alteredBoard.setPiece(piece.withOppositeColor(), at: piece.location)
|
||||
|
||||
return alteredBoard.getPieces(color: piece.color).filter{
|
||||
$0.movement.canPieceMove(fromLocation: $0.location, toLocation: piece.location, board: alteredBoard, accountForCheckState: true)
|
||||
return alteredBoard.getPieces(color: piece.color).filter {
|
||||
$0.movement.canPieceMove(fromLocation: $0.location,
|
||||
toLocation: piece.location,
|
||||
board: alteredBoard,
|
||||
accountForCheckState: true)
|
||||
}
|
||||
}
|
||||
|
||||
func getPieces(protectedBy piece: Piece, onBoard board: Board) -> [Piece] {
|
||||
|
||||
return board.getPieces(color: piece.color).filter{
|
||||
piece.movement.canPieceMove(fromLocation: piece.location, toLocation: $0.location, board: board, accountForCheckState: true)
|
||||
return board.getPieces(color: piece.color).filter {
|
||||
piece.movement.canPieceMove(fromLocation: piece.location,
|
||||
toLocation: $0.location,
|
||||
board: board,
|
||||
accountForCheckState: true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +126,10 @@ class BoardRaterThreatenedPieces : BoardRater {
|
||||
continue
|
||||
}
|
||||
|
||||
if squarePiece.movement.canPieceMove(fromLocation: squarePiece.location, toLocation: piece.location, board: board, accountForCheckState: true) {
|
||||
if squarePiece.movement.canPieceMove(fromLocation: squarePiece.location,
|
||||
toLocation: piece.location,
|
||||
board: board,
|
||||
accountForCheckState: true) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -175,18 +137,23 @@ class BoardRaterThreatenedPieces : BoardRater {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func getPieces(threatening piece: Piece, onBoard board: Board) -> [Piece] {
|
||||
|
||||
return board.getPieces(color: piece.color.opposite()).filter{
|
||||
$0.movement.canPieceMove(fromLocation: $0.location, toLocation: piece.location, board: board, accountForCheckState: true)
|
||||
return board.getPieces(color: piece.color.opposite()).filter {
|
||||
$0.movement.canPieceMove(fromLocation: $0.location,
|
||||
toLocation: piece.location,
|
||||
board: board,
|
||||
accountForCheckState: true)
|
||||
}
|
||||
}
|
||||
|
||||
func getPieces(threatenedBy piece: Piece, onBoard board: Board) -> [Piece] {
|
||||
|
||||
return board.getPieces(color: piece.color.opposite()).filter{
|
||||
piece.movement.canPieceMove(fromLocation: piece.location, toLocation: $0.location, board: board, accountForCheckState: true)
|
||||
return board.getPieces(color: piece.color.opposite()).filter {
|
||||
piece.movement.canPieceMove(fromLocation: piece.location,
|
||||
toLocation: $0.location,
|
||||
board: board,
|
||||
accountForCheckState: true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +161,10 @@ class BoardRaterThreatenedPieces : BoardRater {
|
||||
|
||||
for location in BoardLocation.all {
|
||||
|
||||
if piece.movement.canPieceMove(fromLocation: piece.location, toLocation: location, board: board, accountForCheckState: true) {
|
||||
if piece.movement.canPieceMove(fromLocation: piece.location,
|
||||
toLocation: location,
|
||||
board: board,
|
||||
accountForCheckState: true) {
|
||||
|
||||
var boardCopy = board
|
||||
boardCopy.movePiece(fromLocation: piece.location, toLocation: location)
|
||||
@@ -209,7 +179,7 @@ class BoardRaterThreatenedPieces : BoardRater {
|
||||
}
|
||||
}
|
||||
|
||||
extension Collection where Iterator.Element == Piece{
|
||||
extension Collection where Iterator.Element == Piece {
|
||||
|
||||
func lowestPieceValue() -> Double {
|
||||
|
||||
|
||||
@@ -10,12 +10,11 @@ import Foundation
|
||||
|
||||
public struct BoardStride {
|
||||
|
||||
public var x: Int;
|
||||
public var y: Int;
|
||||
public var x: Int
|
||||
public var y: Int
|
||||
|
||||
public init(x: Int, y: Int){
|
||||
self.x = x;
|
||||
self.y = y;
|
||||
public init(x: Int, y: Int) {
|
||||
self.x = x
|
||||
self.y = y
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ open class Game {
|
||||
case staleMate(color: Color)
|
||||
case won(color: Color)
|
||||
|
||||
public static func ==(lhs: State, rhs: State) -> Bool {
|
||||
public static func == (lhs: State, rhs: State) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case (.inProgress, .inProgress):
|
||||
return true
|
||||
@@ -57,7 +57,10 @@ open class Game {
|
||||
}
|
||||
|
||||
// MARK: Init
|
||||
public init(firstPlayer: Player, secondPlayer: Player, board: Board = Board(state: .newGame), colorToMove: Color = .white){
|
||||
public init(firstPlayer: Player,
|
||||
secondPlayer: Player,
|
||||
board: Board = Board(state: .newGame),
|
||||
colorToMove: Color = .white) {
|
||||
|
||||
self.board = board
|
||||
|
||||
@@ -77,11 +80,10 @@ open class Game {
|
||||
self.currentPlayer = (colorToMove == .white ? self.whitePlayer : self.blackPlayer)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Game : PlayerDelegate
|
||||
extension Game : PlayerDelegate {
|
||||
extension Game: PlayerDelegate {
|
||||
|
||||
func playerDidMakeMove(player: Player, boardOperations: [BoardOperation]) {
|
||||
|
||||
@@ -116,8 +118,7 @@ extension Game : PlayerDelegate {
|
||||
// Switch to the other player
|
||||
if player === whitePlayer {
|
||||
currentPlayer = blackPlayer
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
currentPlayer = whitePlayer
|
||||
}
|
||||
|
||||
@@ -131,11 +132,17 @@ extension Game : PlayerDelegate {
|
||||
|
||||
switch boardOperation.type! {
|
||||
case .movePiece:
|
||||
self.delegate?.gameDidMovePiece(game: self, piece: boardOperation.piece, toLocation: boardOperation.location)
|
||||
self.delegate?.gameDidMovePiece(game: self,
|
||||
piece: boardOperation.piece,
|
||||
toLocation: boardOperation.location)
|
||||
case .removePiece:
|
||||
self.delegate?.gameDidRemovePiece(game: self, piece: boardOperation.piece, location: boardOperation.location)
|
||||
self.delegate?.gameDidRemovePiece(game: self,
|
||||
piece: boardOperation.piece,
|
||||
location: boardOperation.location)
|
||||
case .transformPiece:
|
||||
self.delegate?.gameDidTransformPiece(game: self, piece: boardOperation.piece, location: boardOperation.location)
|
||||
self.delegate?.gameDidTransformPiece(game: self,
|
||||
piece: boardOperation.piece,
|
||||
location: boardOperation.location)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -153,13 +160,23 @@ public protocol GameDelegate: class {
|
||||
func gameEndedInStaleMate(game: Game)
|
||||
|
||||
// Piece adding / removing / modifying
|
||||
func gameWillBeginUpdates(game: Game) // Updates will begin
|
||||
func gameDidAddPiece(game: Game) // A new piece was added to the board (do we actually need to include this functionality?)
|
||||
func gameDidRemovePiece(game: Game, piece: Piece, location: BoardLocation) // A piece was removed from the board
|
||||
func gameDidMovePiece(game: Game, piece: Piece, toLocation: BoardLocation) // A piece was moved on the board
|
||||
func gameDidTransformPiece(game: Game, piece: Piece, location: BoardLocation) // A piece was transformed (eg. pawn was promoted to another piece)
|
||||
func gameDidEndUpdates(game: Game) // Updates will end
|
||||
|
||||
// Updates will begin
|
||||
func gameWillBeginUpdates(game: Game)
|
||||
// A new piece was added to the board
|
||||
func gameDidAddPiece(game: Game)
|
||||
// A piece was removed from the board
|
||||
func gameDidRemovePiece(game: Game, piece: Piece, location: BoardLocation)
|
||||
// A piece was moved on the board
|
||||
func gameDidMovePiece(game: Game, piece: Piece, toLocation: BoardLocation)
|
||||
// A piece was transformed (eg. pawn was promoted to another piece)
|
||||
func gameDidTransformPiece(game: Game, piece: Piece, location: BoardLocation)
|
||||
// Updates will end)
|
||||
func gameDidEndUpdates(game: Game)
|
||||
|
||||
// Callbacks from player
|
||||
func promotedTypeForPawn(location: BoardLocation, player: Human, possiblePromotions: [Piece.PieceType], callback: @escaping (Piece.PieceType) -> Void )
|
||||
func promotedTypeForPawn(location: BoardLocation,
|
||||
player: Human,
|
||||
possiblePromotions: [Piece.PieceType],
|
||||
callback: @escaping (Piece.PieceType) -> Void )
|
||||
}
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
//
|
||||
//
|
||||
|
||||
//swiftlint:disable line_length
|
||||
|
||||
import Foundation
|
||||
|
||||
open class Human : Player {
|
||||
open class Human: Player {
|
||||
|
||||
public init(color: Color){
|
||||
public init(color: Color) {
|
||||
super.init()
|
||||
self.color = color
|
||||
}
|
||||
@@ -49,7 +51,7 @@ open class Human : Player {
|
||||
player: self,
|
||||
possiblePromotions: Piece.PieceType.possiblePawnPromotionResultingTypes(),
|
||||
callback: {
|
||||
|
||||
|
||||
// Change the piece
|
||||
let newPiece = self.game.board.squares[pawnLocation.index].piece?.byChangingType(newType: $0)
|
||||
self.game.board.setPiece(newPiece!, at: pawnLocation)
|
||||
@@ -63,7 +65,7 @@ open class Human : Player {
|
||||
})
|
||||
}
|
||||
// ... Or if no pawn promotions, end move
|
||||
else{
|
||||
else {
|
||||
// Inform the delegate that we made a move
|
||||
delegate?.playerDidMakeMove(player: self, boardOperations: operations)
|
||||
|
||||
@@ -90,7 +92,4 @@ open class Human : Player {
|
||||
delegate?.playerDidMakeMove(player: self, boardOperations: operations)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class Opening {
|
||||
ItalianGame(),
|
||||
SicilianDefense(),
|
||||
QueensGambit(),
|
||||
KingsGambit(),
|
||||
KingsGambit()
|
||||
]
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class Opening {
|
||||
|
||||
var openingMoves = [OpeningMove]()
|
||||
|
||||
allOpenings().forEach{
|
||||
allOpenings().forEach {
|
||||
openingMoves += $0.moves(forColor: color)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class Opening {
|
||||
var moves = [OpeningMove]()
|
||||
|
||||
var board = Board(state: .newGame)
|
||||
for locations in moveLocations(){
|
||||
for locations in moveLocations() {
|
||||
|
||||
let move = OpeningMove(board: board,
|
||||
fromLocation: locations.fromLocation,
|
||||
@@ -57,7 +57,7 @@ class Opening {
|
||||
}
|
||||
|
||||
// Filter for color
|
||||
return moves.enumerated().flatMap{ (index, value) in
|
||||
return moves.enumerated().flatMap { (index, value) in
|
||||
index % 2 == (color == .white ? 0 : 1) ? value : nil
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class Opening {
|
||||
*/
|
||||
func moveLocations() -> [(fromLocation: BoardLocation, toLocation: BoardLocation)] {
|
||||
|
||||
return moveGridPositions().map{
|
||||
return moveGridPositions().map {
|
||||
(BoardLocation(gridPosition: $0), BoardLocation(gridPosition: $1))
|
||||
}
|
||||
}
|
||||
@@ -86,14 +86,15 @@ class Opening {
|
||||
|
||||
class RuyLopez: Opening {
|
||||
|
||||
override func moveGridPositions() -> [(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
override func moveGridPositions() ->
|
||||
[(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
|
||||
let moves: [(BoardLocation.GridPosition, BoardLocation.GridPosition)] = [
|
||||
(.e2, .e4), // white moves pawn to e4
|
||||
(.e7, .e5), // black moves pawn to e5
|
||||
(.g1, .f3), // white moves knight to f3
|
||||
(.b8, .c6), // black moves knight to c6
|
||||
(.f1, .b5), // white moves bishop to b5
|
||||
(.f1, .b5) // white moves bishop to b5
|
||||
]
|
||||
|
||||
return moves
|
||||
@@ -104,14 +105,15 @@ class RuyLopez: Opening {
|
||||
|
||||
class ItalianGame: Opening {
|
||||
|
||||
override func moveGridPositions() -> [(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
override func moveGridPositions() ->
|
||||
[(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
|
||||
let moves: [(BoardLocation.GridPosition, BoardLocation.GridPosition)] = [
|
||||
(.e2, .e4), // white moves pawn to e4
|
||||
(.e7, .e5), // black moves pawn to e5
|
||||
(.g1, .f3), // white moves knight to f3
|
||||
(.b8, .c6), // black moves knight to c6
|
||||
(.f1, .c4), // white moves bishop to c4
|
||||
(.f1, .c4) // white moves bishop to c4
|
||||
]
|
||||
|
||||
return moves
|
||||
@@ -122,11 +124,12 @@ class ItalianGame: Opening {
|
||||
|
||||
class SicilianDefense: Opening {
|
||||
|
||||
override func moveGridPositions() -> [(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
override func moveGridPositions() ->
|
||||
[(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
|
||||
let moves: [(BoardLocation.GridPosition, BoardLocation.GridPosition)] = [
|
||||
(.e2, .e4), // white moves pawn to e4
|
||||
(.c7, .c5), // black moves pawn to c5
|
||||
(.c7, .c5) // black moves pawn to c5
|
||||
]
|
||||
|
||||
return moves
|
||||
@@ -137,12 +140,13 @@ class SicilianDefense: Opening {
|
||||
|
||||
class QueensGambit: Opening {
|
||||
|
||||
override func moveGridPositions() -> [(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
override func moveGridPositions() ->
|
||||
[(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
|
||||
let moves: [(BoardLocation.GridPosition, BoardLocation.GridPosition)] = [
|
||||
(.d2, .d4), // white moves pawn to d4
|
||||
(.d7, .d5), // black moves pawn to d5
|
||||
(.c2, .c4), // white moves pawn to c4
|
||||
(.c2, .c4) // white moves pawn to c4
|
||||
]
|
||||
|
||||
return moves
|
||||
@@ -153,18 +157,15 @@ class QueensGambit: Opening {
|
||||
|
||||
class KingsGambit: Opening {
|
||||
|
||||
override func moveGridPositions() -> [(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
override func moveGridPositions() ->
|
||||
[(fromPosition: BoardLocation.GridPosition, toPosition: BoardLocation.GridPosition)] {
|
||||
|
||||
let moves: [(BoardLocation.GridPosition, BoardLocation.GridPosition)] = [
|
||||
(.e2, .e4), // white moves pawn to e4
|
||||
(.e7, .e5), // black moves pawn to e5
|
||||
(.f2, .f4), // white moves pawn to f4
|
||||
(.f2, .f4) // white moves pawn to f4
|
||||
]
|
||||
|
||||
return moves
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public enum Color: Int {
|
||||
}
|
||||
}
|
||||
|
||||
public struct Piece : Equatable {
|
||||
public struct Piece: Equatable {
|
||||
|
||||
static private var lastAssignedTag = 0
|
||||
|
||||
@@ -49,11 +49,11 @@ public struct Piece : Equatable {
|
||||
public var canBeTakenByEnPassant = false
|
||||
public internal(set) var location = BoardLocation(index: 0)
|
||||
|
||||
var movement : PieceMovement! {
|
||||
var movement: PieceMovement! {
|
||||
return PieceMovement.pieceMovementForPieceType(pieceType: self.type)
|
||||
}
|
||||
|
||||
public init(type: PieceType, color: Color){
|
||||
public init(type: PieceType, color: Color) {
|
||||
self.type = type
|
||||
self.color = color
|
||||
|
||||
@@ -62,7 +62,7 @@ public struct Piece : Equatable {
|
||||
self.tag = Piece.lastAssignedTag
|
||||
}
|
||||
|
||||
public init(type: PieceType, color: Color, tag: Int){
|
||||
public init(type: PieceType, color: Color, tag: Int) {
|
||||
self.type = type
|
||||
self.color = color
|
||||
self.tag = tag
|
||||
@@ -95,8 +95,7 @@ public func == (left: Piece, right: Piece) -> Bool {
|
||||
|
||||
if left.type == right.type && left.color == right.color {
|
||||
return true
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
//
|
||||
//
|
||||
|
||||
//swiftlint:disable file_length
|
||||
|
||||
import Foundation
|
||||
|
||||
// MARK: - PieceMovement (Base Class)
|
||||
@@ -37,11 +39,13 @@ open class PieceMovement {
|
||||
}
|
||||
}
|
||||
|
||||
public init(){
|
||||
|
||||
public init() {
|
||||
}
|
||||
|
||||
func canPieceMove(fromLocation: BoardLocation, toLocation: BoardLocation, board: Board, accountForCheckState: Bool = false) -> Bool {
|
||||
func canPieceMove(fromLocation: BoardLocation,
|
||||
toLocation: BoardLocation,
|
||||
board: Board,
|
||||
accountForCheckState: Bool = false) -> Bool {
|
||||
|
||||
if fromLocation == toLocation {
|
||||
return false
|
||||
@@ -56,8 +60,7 @@ open class PieceMovement {
|
||||
var boardCopy = board
|
||||
boardCopy.movePiece(fromLocation: fromLocation, toLocation: toLocation)
|
||||
return boardCopy.isColorInCheck(color: color) ? false : true
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return canMove
|
||||
}
|
||||
}
|
||||
@@ -66,9 +69,13 @@ open class PieceMovement {
|
||||
return false
|
||||
}
|
||||
|
||||
func canPieceMove(fromLocation: BoardLocation, toLocation: BoardLocation, board: Board, stride: BoardStride) -> Bool {
|
||||
// swiftlint:disable function_body_length
|
||||
func canPieceMove(fromLocation: BoardLocation,
|
||||
toLocation: BoardLocation,
|
||||
board: Board,
|
||||
stride: BoardStride) -> Bool {
|
||||
|
||||
enum Direction: Int{
|
||||
enum Direction: Int {
|
||||
case increasing
|
||||
case decresing
|
||||
case none
|
||||
@@ -150,12 +157,12 @@ open class PieceMovement {
|
||||
return false
|
||||
}
|
||||
|
||||
func canPieceOccupySquare(pieceLocation: BoardLocation, xOffset: Int, yOffset: Int, board: Board) -> Bool{
|
||||
func canPieceOccupySquare(pieceLocation: BoardLocation, xOffset: Int, yOffset: Int, board: Board) -> Bool {
|
||||
|
||||
let targetLocation = pieceLocation.incrementedBy(x: xOffset, y: yOffset)
|
||||
|
||||
// Check if in bounds
|
||||
guard targetLocation.isInBounds() else{
|
||||
guard targetLocation.isInBounds() else {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -246,7 +253,7 @@ open class PieceMovementDiagonal: PieceMovement {
|
||||
|
||||
open class PieceMovementQueen: PieceMovement {
|
||||
|
||||
let movements : [PieceMovement] = [PieceMovementStraightLine(), PieceMovementDiagonal()]
|
||||
let movements: [PieceMovement] = [PieceMovementStraightLine(), PieceMovementDiagonal()]
|
||||
|
||||
override func isMovementPossible(fromLocation: BoardLocation, toLocation: BoardLocation, board: Board) -> Bool {
|
||||
|
||||
@@ -291,14 +298,14 @@ open class PieceMovementBishop: PieceMovement {
|
||||
open class PieceMovementKnight: PieceMovement {
|
||||
|
||||
let offsets: [(x: Int, y: Int)] = [
|
||||
(1,2),
|
||||
(2,1),
|
||||
(2,-1),
|
||||
(-2,1),
|
||||
(-1,-2),
|
||||
(-2,-1),
|
||||
(1,-2),
|
||||
(-1,2)
|
||||
(1, 2),
|
||||
(2, 1),
|
||||
(2, -1),
|
||||
(-2, 1),
|
||||
(-1, -2),
|
||||
(-2, -1),
|
||||
(1, -2),
|
||||
(-1, 2)
|
||||
]
|
||||
|
||||
override func isMovementPossible(fromLocation: BoardLocation, toLocation: BoardLocation, board: Board) -> Bool {
|
||||
@@ -315,7 +322,10 @@ open class PieceMovementKnight: PieceMovement {
|
||||
let offsetLocation = fromLocation.incrementedBy(x: offset.x, y: offset.y)
|
||||
|
||||
if toLocation == offsetLocation
|
||||
&& canPieceOccupySquare(pieceLocation: fromLocation, xOffset: offset.x, yOffset: offset.y, board: board) {
|
||||
&& canPieceOccupySquare(pieceLocation: fromLocation,
|
||||
xOffset: offset.x,
|
||||
yOffset: offset.y,
|
||||
board: board) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -327,12 +337,13 @@ open class PieceMovementKnight: PieceMovement {
|
||||
|
||||
// MARK: - PieceMovementPawn
|
||||
|
||||
// swiftlint:disable function_body_length
|
||||
open class PieceMovementPawn: PieceMovement {
|
||||
|
||||
override func isMovementPossible(fromLocation: BoardLocation, toLocation: BoardLocation, board: Board) -> Bool {
|
||||
|
||||
// Get the moving piece
|
||||
guard let movingPiece = board.getPiece(at: fromLocation) else{
|
||||
guard let movingPiece = board.getPiece(at: fromLocation) else {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -354,7 +365,6 @@ open class PieceMovementPawn: PieceMovement {
|
||||
let color = movingPiece.color
|
||||
|
||||
// ****** Test forward locations ******
|
||||
var forwardStrides = [BoardStride]()
|
||||
|
||||
// Test one ahead offset
|
||||
let oneAheadStride = (color == .white ? BoardStride(x: 0, y: 1) : BoardStride(x: 0, y: -1))
|
||||
@@ -364,7 +374,7 @@ open class PieceMovementPawn: PieceMovement {
|
||||
|
||||
let location = fromLocation.incrementedBy(stride: oneAheadStride)
|
||||
|
||||
if let _ = board.getPiece(at: location) {
|
||||
if board.getPiece(at: location) != nil {
|
||||
canMoveOneAhead = false
|
||||
break ONE_AHEAD
|
||||
}
|
||||
@@ -374,7 +384,6 @@ open class PieceMovementPawn: PieceMovement {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Test two ahead offset
|
||||
if canMoveOneAhead {
|
||||
|
||||
@@ -382,8 +391,7 @@ open class PieceMovementPawn: PieceMovement {
|
||||
|
||||
if color == .white && fromLocation.y == 1 {
|
||||
twoAheadStride = BoardStride(x: 0, y: 2)
|
||||
}
|
||||
else if color == .black && fromLocation.y == 6 {
|
||||
} else if color == .black && fromLocation.y == 6 {
|
||||
twoAheadStride = BoardStride(x: 0, y: -2)
|
||||
}
|
||||
|
||||
@@ -407,8 +415,7 @@ open class PieceMovementPawn: PieceMovement {
|
||||
if color == .white {
|
||||
diagonalStrides.append( BoardStride(x: -1, y: 1) )
|
||||
diagonalStrides.append( BoardStride(x: 1, y: 1) )
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
diagonalStrides.append( BoardStride(x: -1, y: -1) )
|
||||
diagonalStrides.append( BoardStride(x: 1, y: -1) )
|
||||
}
|
||||
@@ -456,20 +463,19 @@ open class PieceMovementPawn: PieceMovement {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - PieceMovementKing
|
||||
|
||||
open class PieceMovementKing: PieceMovement {
|
||||
|
||||
let offsets: [(x: Int, y: Int)] = [
|
||||
(0,1), // North
|
||||
(1,1), // North-East
|
||||
(1,0), // East
|
||||
(1,-1), // South-East
|
||||
(0,-1), // South
|
||||
(-1,-1), // South-West
|
||||
(-1,0), // West
|
||||
(-1,1) // North- West
|
||||
(0, 1), // North
|
||||
(1, 1), // North-East
|
||||
(1, 0), // East
|
||||
(1, -1), // South-East
|
||||
(0, -1), // South
|
||||
(-1, -1), // South-West
|
||||
(-1, 0), // West
|
||||
(-1, 1) // North- West
|
||||
]
|
||||
|
||||
override func isMovementPossible(fromLocation: BoardLocation, toLocation: BoardLocation, board: Board) -> Bool {
|
||||
@@ -487,7 +493,10 @@ open class PieceMovementKing: PieceMovement {
|
||||
|
||||
if toLocation == offsetLocation
|
||||
&& offsetLocation.isInBounds()
|
||||
&& canPieceOccupySquare(pieceLocation: fromLocation, xOffset: offset.x, yOffset: offset.y, board: board) {
|
||||
&& canPieceOccupySquare(pieceLocation: fromLocation,
|
||||
xOffset: offset.x,
|
||||
yOffset: offset.y,
|
||||
board: board) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ open class Player {
|
||||
weak var game: Game!
|
||||
weak var delegate: PlayerDelegate?
|
||||
|
||||
public func occupiesSquareAt(location: BoardLocation) -> Bool{
|
||||
public func occupiesSquareAt(location: BoardLocation) -> Bool {
|
||||
|
||||
if let piece = self.game.board.getPiece(at: location){
|
||||
if let piece = self.game.board.getPiece(at: location) {
|
||||
if piece.color == self.color {
|
||||
return true
|
||||
}
|
||||
@@ -33,7 +33,7 @@ open class Player {
|
||||
return canMovePieceWithError(fromLocation: fromLocation, toLocation: toLocation).result
|
||||
}
|
||||
|
||||
public enum MoveError : Error {
|
||||
public enum MoveError: Error {
|
||||
case notThisPlayersTurn
|
||||
case movingToSameLocation
|
||||
case noPieceToMove
|
||||
@@ -44,7 +44,8 @@ open class Player {
|
||||
case gameIsNotInProgress
|
||||
}
|
||||
|
||||
public func canMovePieceWithError(fromLocation: BoardLocation, toLocation: BoardLocation) -> (result: Bool, error: MoveError?) {
|
||||
public func canMovePieceWithError(fromLocation: BoardLocation, toLocation: BoardLocation) ->
|
||||
(result: Bool, error: MoveError?) {
|
||||
|
||||
// We can't move to our current location
|
||||
if fromLocation == toLocation {
|
||||
@@ -83,7 +84,4 @@ open class Player {
|
||||
|
||||
return (true, nil)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
67A9C9DA1DE64CD200510FB8 /* Frameworks */,
|
||||
67A9C9DB1DE64CD200510FB8 /* Headers */,
|
||||
67A9C9DC1DE64CD200510FB8 /* Resources */,
|
||||
67B663191F9939A4004621B2 /* Swift Lint */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@@ -246,15 +247,17 @@
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0800;
|
||||
LastUpgradeCheck = 0800;
|
||||
LastUpgradeCheck = 0900;
|
||||
ORGANIZATIONNAME = "Steve Barnegren";
|
||||
TargetAttributes = {
|
||||
67A9C9DD1DE64CD200510FB8 = {
|
||||
CreatedOnToolsVersion = 8.0;
|
||||
LastSwiftMigration = 0900;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
67A9C9E61DE64CD300510FB8 = {
|
||||
CreatedOnToolsVersion = 8.0;
|
||||
LastSwiftMigration = 0900;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
};
|
||||
@@ -294,6 +297,23 @@
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
67B663191F9939A4004621B2 /* Swift Lint */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
);
|
||||
name = "Swift Lint";
|
||||
outputPaths = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
67A9C9D91DE64CD200510FB8 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
@@ -351,7 +371,9 @@
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
@@ -359,7 +381,12 @@
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
@@ -404,7 +431,9 @@
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
@@ -412,7 +441,12 @@
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
@@ -455,7 +489,8 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.SwiftChess;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 3.0;
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
SWIFT_VERSION = 4.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -473,7 +508,8 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.SwiftChess;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 3.0;
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
SWIFT_VERSION = 4.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@@ -485,7 +521,8 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.SwiftChessTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_VERSION = 4.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -497,7 +534,8 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = SteveBarnegren.SwiftChessTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = On;
|
||||
SWIFT_VERSION = 4.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Example/Pods/Pods.xcodeproj
|
||||
Reference in New Issue
Block a user