ios


Code error in Tic-Tac-Toe game


I would really appreciate your help with the following. I have been battling this small nuisance for a while now but without luck. I have this bit of code thats basically simulates a AI playing TIC TAC TOE against a player.
let Result = RowCheck(value: 0)
if Result != nil {
println("Computer has two in a row")
var WhereToPlayResult = WhereToPlay(Result.location, pattern: Result.pattern)
if !IsOccupied(WhereToPlayResult) {
SetImageForSpot(WhereToPlayResult, player: 0)
aiDeciding = false
CheckForWin()
return
}
return
}
RowCheck just checks for a pattern to play against.
func RowCheck(#‎value:Int) -> (location:String,pattern:String)? {
var AcceptableFinds = ["011","110","101"]
var FindFuncs = [CheckTop,CheckBottom,CheckLeft,CheckRight,CheckMiddleAcross,CheckMiddleDown,CheckDiagionalRightLeft,CheckDiagionalLeftRight]
for Algorthm in FindFuncs {
var AlgorthmResults = Algorthm(value:value)
if (find(AcceptableFinds,AlgorthmResults.pattern) != nil) {
return AlgorthmResults
}
}
return nil
}
But it gives me an error at:
var WhereToPlayResult = WhereToPlay(Result.location, pattern: Result.pattern)
Because your RowCheck method returns an optional (and might return nil), you need to either unwrap your optional or use a different assignment:
let Result = RowCheck(value: 0)
if Result != nil {
var WhereToPlayResult = WhereToPlay(Result!.location, pattern: Result!.pattern)
// ... ^ ^
}
if let Result = RowCheck(value: 0) {
// ...
}
Side note: only classes should be named starting with a capital letter. To stay within Apple's code style, you should variables and functions as result, rowCheck, etc.

Related Links

XCode iOS Simulator 'Cannot Boot' error and lockout/bug
Loop through [[String: Any]]
How to get .CSV file in real iPAD device?
Presented View Controller Status Bar Color is Different, How to Change It To Default?
Error Sigabrt with Google Sign In Xcode
Alamofire 4 FAILURE With Swift 3.0 : Error Domain=NSURLErrorDomain Code=-999 “cancelled”
How to kill camera process in iPhone through our app
How exactly does Realm() work?
WKWebView Inside UIScrollView: Scrolling Conflict
Does Firebase 3.7.0 support in iOS 7 and 8
UIRefreshControl not Dissapearing
Need help to declare array for plist info retrieval in Swift 3 [duplicate]
Memory leak in NSJSONSerialization method?
Xcode 8 how to show description of function while typing
Create a nested child node in Firebase using Firebase 3.x
FBSDKLoginKit not redirect my app after login and confirm page

Categories

HOME
ssl
jsp
clojure
simulated-annealing
identityserver4
prebuild
chronicle
amazon-kinesis
normalization
textbox
ionic3
webdriver-io
sony-camera-api
splunk
player-swift
zipfile
windows-10-desktop
deserialization
git-svn
export-to-excel
aar
amadeus
records
javers
slowcheetah
curve-fitting
jpos
c-strings
cadvisor
scalability
ucwa
flexjs
f2py
svn2git
stl
akka-http
scatter-plot
django-users
imageshack
codeskulptor
capstone
gradient-descent
eve
linear
mediawiki-api
virtualmin
mobile-browser
kendo-chart
simplesamlphp
scoring
sharpziplib
soql
infiniband
ice
haste
lapply
vistadb
rails-console
cufft
pager
pypyodbc
airplay
administrator
tag-helpers
radix-sort
linqtocsv
tun
axlsx
multiscreen
viennacl
dhc
wintersmith
wso2as
declaration
iife
vendor
isql
modern-ui
spiceworks
jet.com-apis
iqueryable
bunny
grunt-contrib-copy
b2b
srp
jxta
xcache
hresult
jquery-data
jflow
nspersistentdocument
memento
blackberry-cascades
makumba
mknetworkkit
duplicate-data
springboard
retain
hunchentoot
rails-3.1
mkmapviewdelegate
adbwireless
seam-conversation
arraycopy
gumstix
geneva-framework
run-length-encoding
newsgroup
user-testing

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App