home *** CD-ROM | disk | FTP | other *** search
- on drawPathArrows
- global pathIndex, tileSO, tileSize, moveType, boardData, moveTestPositions, moveTestResults
- tileLocPointer = the mouseLoc - the loc of sprite tileSO
- tileLocPointer = (tileLocPointer / tileSize) + point(1, 1)
- repeat with whichpath = 1 to 8
- wSprite = 200 + whichpath
- if whichpath < count(pathIndex) then
- set the loc of sprite wSprite to (pathIndex[whichpath] * tileSize) + the loc of sprite tileSO - (tileSize / 2)
- theAngle = findAngle(pathIndex[whichpath], pathIndex[whichpath + 1])
- theDist = findDistance(pathIndex[whichpath] * tileSize, pathIndex[whichpath + 1] * tileSize)
- sprite(wSprite).rotation = theAngle
- set the width of sprite wSprite to 15
- set the height of sprite wSprite to theDist
- set the member of sprite wSprite to "Arrow"
- next repeat
- end if
- if whichpath = count(pathIndex) then
- validMove = 0
- repeat with whichV = 1 to count(moveTestPositions)
- if moveTestPositions[whichV] = tileLocPointer then
- validMove = 1
- if moveType = VOID then
- g = moveTestResults[whichV]
- end if
- end if
- end repeat
- theAngle = findAngle(pathIndex[whichpath], tileLocPointer)
- theDist = findDistance(pathIndex[whichpath] * tileSize, tileLocPointer * tileSize)
- next repeat
- end if
- set the loc of sprite wSprite to point(-50, -50)
- sprite(wSprite).rotation = 0
- set the height of sprite wSprite to 5
- set the width of sprite wSprite to 15
- end repeat
- end
-
- on executePlayerMoves
- global moveTestResults, moveTestPositions, smartyJumps, smartyMoves, boardData, pathIndex, moveType, playerTMoves, attackSoundRegistered
- moveOfChoice = pathIndex
- whichSide = 1
- if count(pathIndex) > 1 then
- playerTMoves = playerTMoves + 1
- if moveType = #move then
- pType = boardData[pathIndex[1][2]][pathIndex[1][1]]
- boardData[pathIndex[1][2]][pathIndex[1][1]] = [0, 0]
- boardData[pathIndex[2][2]][pathIndex[2][1]] = pType
- else
- attackSoundRegistered = 1
- pType = boardData[moveOfChoice[1][2]][moveOfChoice[1][1]]
- boardData[moveOfChoice[1][2]][moveOfChoice[1][1]] = [0, 0]
- repeat with whichLoc = 1 to count(moveOfChoice) - 1
- newloc = (moveOfChoice[whichLoc] + moveOfChoice[whichLoc + 1]) / 2
- boardData[newloc[2]][newloc[1]] = [0, 0]
- end repeat
- lastLoc = moveOfChoice[count(moveOfChoice)]
- boardData[lastLoc[2]][lastLoc[1]] = pType
- pathIndex = []
- end if
- else
- end if
- repeat with whichX = 1 to count(boardData[1])
- if boardData[1][whichX] = #Bp then
- boardData[1][whichX] = #Bk
- playSound("king checker SFX", 2)
- end if
- end repeat
- end
-
- on calculateAllMoves whichSide, onlyATest
- global moveTestResults, moveTestPositions, smartyJumps, smartyMoves, boardData, pathIndex, mustGiveUp
- clearOldAIcheck()
- mustGiveUp = 0
- repeat with whichY = 1 to count(boardData)
- repeat with whichX = 1 to count(boardData[1])
- pDataBit = returnPiece([whichX, whichY])
- if pDataBit[2] = whichSide then
- runAIcheck(point(whichX, whichY))
- end if
- end repeat
- end repeat
- if smartyJumps > 1 then
- if onlyATest <> 1 then
- moveOfChoice = smartyMoves[random(count(smartyMoves))]
- pathIndex = moveOfChoice
- pType = boardData[moveOfChoice[1][2]][moveOfChoice[1][1]]
- boardData[moveOfChoice[1][2]][moveOfChoice[1][1]] = [0, 0]
- repeat with whichLoc = 1 to count(moveOfChoice) - 1
- newloc = (moveOfChoice[whichLoc] + moveOfChoice[whichLoc + 1]) / 2
- boardData[newloc[2]][newloc[1]] = [0, 0]
- end repeat
- lastLoc = moveOfChoice[count(moveOfChoice)]
- boardData[lastLoc[2]][lastLoc[1]] = pType
- end if
- else
- possibleMoves = []
- repeat with whichY = 1 to count(boardData)
- repeat with whichX = 1 to count(boardData[1])
- centerPoint = point(whichX, whichY)
- bitData = boardData[whichY][whichX]
- bitStat = returnPiece(centerPoint)
- if bitStat[2] = whichSide then
- testJumps(centerPoint)
- repeat with wVector = 1 to 4
- if moveTestResults[wVector] = #move then
- add(possibleMoves, [centerPoint, moveTestPositions[wVector]])
- end if
- end repeat
- end if
- end repeat
- end repeat
- if count(possibleMoves) > 1 then
- moveOfChoice = possibleMoves[random(count(possibleMoves))]
- else
- if count(possibleMoves) = 1 then
- moveOfChoice = possibleMoves[1]
- else
- moveOfChoice = #Na
- end if
- end if
- if moveOfChoice <> #Na then
- if onlyATest <> 1 then
- pType = boardData[moveOfChoice[1][2]][moveOfChoice[1][1]]
- boardData[moveOfChoice[1][2]][moveOfChoice[1][1]] = [0, 0]
- lastLoc = moveOfChoice[count(moveOfChoice)]
- boardData[lastLoc[2]][lastLoc[1]] = pType
- pathIndex = moveOfChoice
- end if
- else
- mustGiveUp = 1
- end if
- end if
- if onlyATest = 0 then
- enemyLines = count(boardData[1])
- repeat with whichX = 1 to count(boardData[1])
- if boardData[enemyLines][whichX] = #Rp then
- boardData[enemyLines][whichX] = #Rk
- playSound("king checker SFX", 2)
- redrawBoard()
- end if
- end repeat
- else
- return mustGiveUp
- end if
- end
-
- on clearOldAIcheck
- global smartyJumps, smartyMoves
- smartyJumps = 0
- smartyMoves = []
- end
-
- on runAIcheck checkLoc, moveState
- global moveTestResults, moveTestPositions, compiledMoves, boardData, smartyJumps, smartyMoves
- checkVectors = 0
- compiledMoves = []
- incompleteMoves = []
- add(incompleteMoves, [checkLoc])
- moveCheckup = incompleteMoves
- starterPiece = returnPiece(checkLoc)
- repeat with whichRep = 1 to 3
- if count(incompleteMoves) > 0 then
- testEntry = incompleteMoves[1]
- testVector = testEntry[count(testEntry)]
- testJumps(testVector, starterPiece)
- newEntryLists = []
- repeat with whichV = 1 to 4
- tempEntry = []
- repeat with whichX = 1 to count(testEntry)
- add(tempEntry, testEntry[whichX])
- end repeat
- prohibited = 0
- repeat with multiTest = 1 to count(tempEntry)
- if moveTestPositions[multiTest] = tempEntry then
- prohibited = 1
- end if
- end repeat
- if (moveTestResults[whichV] = #Attack) and (prohibited = 0) then
- add(tempEntry, moveTestPositions[whichV])
- add(newEntryLists, tempEntry)
- add(moveCheckup, tempEntry)
- end if
- end repeat
- repeat while count(newEntryLists) > 0
- if count(newEntryLists[1]) > 0 then
- add(compiledMoves, newEntryLists[1])
- else
- add(incompleteMoves, newEntryLists[1])
- end if
- deleteAt(newEntryLists, 1)
- end repeat
- deleteAt(incompleteMoves, 1)
- end if
- end repeat
- repeat with whichX = 1 to count(compiledMoves)
- if count(compiledMoves[whichX]) > smartyJumps then
- smartyJumps = count(compiledMoves[whichX])
- end if
- end repeat
- repeat with whichX = 1 to count(compiledMoves)
- if count(compiledMoves[whichX]) = smartyJumps then
- add(smartyMoves, compiledMoves[whichX])
- end if
- end repeat
- return smartyMoves
- end
-
- on checkGameComplete
- global boardData, totalpieces, playerTMoves, playerTCaptures, playerTLosses
- redActive = 0
- blackActive = 0
- totalRed = 0
- totalBlack = 0
- repeat with whichY = 1 to count(boardData)
- repeat with whichX = 1 to count(boardData[1])
- results = returnPiece(point(whichY, whichX))
- if results[2] = 1 then
- redActive = 1
- totalRed = totalRed + 1
- next repeat
- end if
- if results[2] = 2 then
- blackActive = 1
- totalBlack = totalBlack + 1
- end if
- end repeat
- end repeat
- playerTLosses = totalpieces - totalBlack
- playerTCaptures = totalpieces - totalRed
- member("Losses").text = string(playerTLosses)
- member("Captures").text = string(playerTCaptures)
- member("Moves").text = string(playerTMoves)
- return [redActive, blackActive]
- end
-
- on antiNest nestedList
- newList = nestedList[1]
- append(newList, nestedList[2])
- return newList
- end
-