home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / CheckersSparse.dxr / 00013.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  8.0 KB  |  241 lines

  1. on drawPathArrows
  2.   global pathIndex, tileSO, tileSize, moveType, boardData, moveTestPositions, moveTestResults
  3.   tileLocPointer = the mouseLoc - the loc of sprite tileSO
  4.   tileLocPointer = (tileLocPointer / tileSize) + point(1, 1)
  5.   repeat with whichpath = 1 to 8
  6.     wSprite = 200 + whichpath
  7.     if whichpath < count(pathIndex) then
  8.       set the loc of sprite wSprite to (pathIndex[whichpath] * tileSize) + the loc of sprite tileSO - (tileSize / 2)
  9.       theAngle = findAngle(pathIndex[whichpath], pathIndex[whichpath + 1])
  10.       theDist = findDistance(pathIndex[whichpath] * tileSize, pathIndex[whichpath + 1] * tileSize)
  11.       sprite(wSprite).rotation = theAngle
  12.       set the width of sprite wSprite to 15
  13.       set the height of sprite wSprite to theDist
  14.       set the member of sprite wSprite to "Arrow"
  15.       next repeat
  16.     end if
  17.     if whichpath = count(pathIndex) then
  18.       validMove = 0
  19.       repeat with whichV = 1 to count(moveTestPositions)
  20.         if moveTestPositions[whichV] = tileLocPointer then
  21.           validMove = 1
  22.           if moveType = VOID then
  23.             g = moveTestResults[whichV]
  24.           end if
  25.         end if
  26.       end repeat
  27.       theAngle = findAngle(pathIndex[whichpath], tileLocPointer)
  28.       theDist = findDistance(pathIndex[whichpath] * tileSize, tileLocPointer * tileSize)
  29.       next repeat
  30.     end if
  31.     set the loc of sprite wSprite to point(-50, -50)
  32.     sprite(wSprite).rotation = 0
  33.     set the height of sprite wSprite to 5
  34.     set the width of sprite wSprite to 15
  35.   end repeat
  36. end
  37.  
  38. on executePlayerMoves
  39.   global moveTestResults, moveTestPositions, smartyJumps, smartyMoves, boardData, pathIndex, moveType, playerTMoves, attackSoundRegistered
  40.   moveOfChoice = pathIndex
  41.   whichSide = 1
  42.   if count(pathIndex) > 1 then
  43.     playerTMoves = playerTMoves + 1
  44.     if moveType = #move then
  45.       pType = boardData[pathIndex[1][2]][pathIndex[1][1]]
  46.       boardData[pathIndex[1][2]][pathIndex[1][1]] = [0, 0]
  47.       boardData[pathIndex[2][2]][pathIndex[2][1]] = pType
  48.     else
  49.       attackSoundRegistered = 1
  50.       pType = boardData[moveOfChoice[1][2]][moveOfChoice[1][1]]
  51.       boardData[moveOfChoice[1][2]][moveOfChoice[1][1]] = [0, 0]
  52.       repeat with whichLoc = 1 to count(moveOfChoice) - 1
  53.         newloc = (moveOfChoice[whichLoc] + moveOfChoice[whichLoc + 1]) / 2
  54.         boardData[newloc[2]][newloc[1]] = [0, 0]
  55.       end repeat
  56.       lastLoc = moveOfChoice[count(moveOfChoice)]
  57.       boardData[lastLoc[2]][lastLoc[1]] = pType
  58.       pathIndex = []
  59.     end if
  60.   else
  61.   end if
  62.   repeat with whichX = 1 to count(boardData[1])
  63.     if boardData[1][whichX] = #Bp then
  64.       boardData[1][whichX] = #Bk
  65.       playSound("king checker SFX", 2)
  66.     end if
  67.   end repeat
  68. end
  69.  
  70. on calculateAllMoves whichSide, onlyATest
  71.   global moveTestResults, moveTestPositions, smartyJumps, smartyMoves, boardData, pathIndex, mustGiveUp
  72.   clearOldAIcheck()
  73.   mustGiveUp = 0
  74.   repeat with whichY = 1 to count(boardData)
  75.     repeat with whichX = 1 to count(boardData[1])
  76.       pDataBit = returnPiece([whichX, whichY])
  77.       if pDataBit[2] = whichSide then
  78.         runAIcheck(point(whichX, whichY))
  79.       end if
  80.     end repeat
  81.   end repeat
  82.   if smartyJumps > 1 then
  83.     if onlyATest <> 1 then
  84.       moveOfChoice = smartyMoves[random(count(smartyMoves))]
  85.       pathIndex = moveOfChoice
  86.       pType = boardData[moveOfChoice[1][2]][moveOfChoice[1][1]]
  87.       boardData[moveOfChoice[1][2]][moveOfChoice[1][1]] = [0, 0]
  88.       repeat with whichLoc = 1 to count(moveOfChoice) - 1
  89.         newloc = (moveOfChoice[whichLoc] + moveOfChoice[whichLoc + 1]) / 2
  90.         boardData[newloc[2]][newloc[1]] = [0, 0]
  91.       end repeat
  92.       lastLoc = moveOfChoice[count(moveOfChoice)]
  93.       boardData[lastLoc[2]][lastLoc[1]] = pType
  94.     end if
  95.   else
  96.     possibleMoves = []
  97.     repeat with whichY = 1 to count(boardData)
  98.       repeat with whichX = 1 to count(boardData[1])
  99.         centerPoint = point(whichX, whichY)
  100.         bitData = boardData[whichY][whichX]
  101.         bitStat = returnPiece(centerPoint)
  102.         if bitStat[2] = whichSide then
  103.           testJumps(centerPoint)
  104.           repeat with wVector = 1 to 4
  105.             if moveTestResults[wVector] = #move then
  106.               add(possibleMoves, [centerPoint, moveTestPositions[wVector]])
  107.             end if
  108.           end repeat
  109.         end if
  110.       end repeat
  111.     end repeat
  112.     if count(possibleMoves) > 1 then
  113.       moveOfChoice = possibleMoves[random(count(possibleMoves))]
  114.     else
  115.       if count(possibleMoves) = 1 then
  116.         moveOfChoice = possibleMoves[1]
  117.       else
  118.         moveOfChoice = #Na
  119.       end if
  120.     end if
  121.     if moveOfChoice <> #Na then
  122.       if onlyATest <> 1 then
  123.         pType = boardData[moveOfChoice[1][2]][moveOfChoice[1][1]]
  124.         boardData[moveOfChoice[1][2]][moveOfChoice[1][1]] = [0, 0]
  125.         lastLoc = moveOfChoice[count(moveOfChoice)]
  126.         boardData[lastLoc[2]][lastLoc[1]] = pType
  127.         pathIndex = moveOfChoice
  128.       end if
  129.     else
  130.       mustGiveUp = 1
  131.     end if
  132.   end if
  133.   if onlyATest = 0 then
  134.     enemyLines = count(boardData[1])
  135.     repeat with whichX = 1 to count(boardData[1])
  136.       if boardData[enemyLines][whichX] = #Rp then
  137.         boardData[enemyLines][whichX] = #Rk
  138.         playSound("king checker SFX", 2)
  139.         redrawBoard()
  140.       end if
  141.     end repeat
  142.   else
  143.     return mustGiveUp
  144.   end if
  145. end
  146.  
  147. on clearOldAIcheck
  148.   global smartyJumps, smartyMoves
  149.   smartyJumps = 0
  150.   smartyMoves = []
  151. end
  152.  
  153. on runAIcheck checkLoc, moveState
  154.   global moveTestResults, moveTestPositions, compiledMoves, boardData, smartyJumps, smartyMoves
  155.   checkVectors = 0
  156.   compiledMoves = []
  157.   incompleteMoves = []
  158.   add(incompleteMoves, [checkLoc])
  159.   moveCheckup = incompleteMoves
  160.   starterPiece = returnPiece(checkLoc)
  161.   repeat with whichRep = 1 to 3
  162.     if count(incompleteMoves) > 0 then
  163.       testEntry = incompleteMoves[1]
  164.       testVector = testEntry[count(testEntry)]
  165.       testJumps(testVector, starterPiece)
  166.       newEntryLists = []
  167.       repeat with whichV = 1 to 4
  168.         tempEntry = []
  169.         repeat with whichX = 1 to count(testEntry)
  170.           add(tempEntry, testEntry[whichX])
  171.         end repeat
  172.         prohibited = 0
  173.         repeat with multiTest = 1 to count(tempEntry)
  174.           if moveTestPositions[multiTest] = tempEntry then
  175.             prohibited = 1
  176.           end if
  177.         end repeat
  178.         if (moveTestResults[whichV] = #Attack) and (prohibited = 0) then
  179.           add(tempEntry, moveTestPositions[whichV])
  180.           add(newEntryLists, tempEntry)
  181.           add(moveCheckup, tempEntry)
  182.         end if
  183.       end repeat
  184.       repeat while count(newEntryLists) > 0
  185.         if count(newEntryLists[1]) > 0 then
  186.           add(compiledMoves, newEntryLists[1])
  187.         else
  188.           add(incompleteMoves, newEntryLists[1])
  189.         end if
  190.         deleteAt(newEntryLists, 1)
  191.       end repeat
  192.       deleteAt(incompleteMoves, 1)
  193.     end if
  194.   end repeat
  195.   repeat with whichX = 1 to count(compiledMoves)
  196.     if count(compiledMoves[whichX]) > smartyJumps then
  197.       smartyJumps = count(compiledMoves[whichX])
  198.     end if
  199.   end repeat
  200.   repeat with whichX = 1 to count(compiledMoves)
  201.     if count(compiledMoves[whichX]) = smartyJumps then
  202.       add(smartyMoves, compiledMoves[whichX])
  203.     end if
  204.   end repeat
  205.   return smartyMoves
  206. end
  207.  
  208. on checkGameComplete
  209.   global boardData, totalpieces, playerTMoves, playerTCaptures, playerTLosses
  210.   redActive = 0
  211.   blackActive = 0
  212.   totalRed = 0
  213.   totalBlack = 0
  214.   repeat with whichY = 1 to count(boardData)
  215.     repeat with whichX = 1 to count(boardData[1])
  216.       results = returnPiece(point(whichY, whichX))
  217.       if results[2] = 1 then
  218.         redActive = 1
  219.         totalRed = totalRed + 1
  220.         next repeat
  221.       end if
  222.       if results[2] = 2 then
  223.         blackActive = 1
  224.         totalBlack = totalBlack + 1
  225.       end if
  226.     end repeat
  227.   end repeat
  228.   playerTLosses = totalpieces - totalBlack
  229.   playerTCaptures = totalpieces - totalRed
  230.   member("Losses").text = string(playerTLosses)
  231.   member("Captures").text = string(playerTCaptures)
  232.   member("Moves").text = string(playerTMoves)
  233.   return [redActive, blackActive]
  234. end
  235.  
  236. on antiNest nestedList
  237.   newList = nestedList[1]
  238.   append(newList, nestedList[2])
  239.   return newList
  240. end
  241.