Permalink
Browse files

Added a few more rules , I havent worked out a generic method for the…

… rules , but at least there is a pattern to follow when creating them
  • Loading branch information...
1 parent 7e0e5f3 commit 8a782854481658b2463242faaf4d76ac229ad799 RC1140 committed Mar 21, 2012
Showing with 123 additions and 29 deletions.
  1. +123 −29 bot.au3
View
152 bot.au3
@@ -13,77 +13,171 @@ Func buildColorMap()
Return $ucm
EndFunc
+;This checks for a match downwards to the right of the current block
+Func checkMatchDownRight($coloredMap,$x,$y)
+ if $y < 7 Then
+ if $x < 6 Then
+ if $coloredMap[$y][$x] == $coloredMap[$y+1][$x+2] Then
+ if $coloredMap[$y+1][$x+1] == $coloredMap[$y][$x] Then
+ ConsoleWrite(@LF )
+ ConsoleWrite(" Row Match 3 down right")
+ MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +1) * 37) - 11 )
+ MouseClick ( "left" ,$coord[0] + 18 +( $x * 37), $coord[1] + ( ($y +2) * 37) - 11 )
+ Return True
+ ;~ Else
+ ;~ ConsoleWrite($coloredMap[$y+1][$x+1]& " , ")
+ ;~ ConsoleWrite($coloredMap[$y+1][$x+2]& " , ")
+ EndIf
+ EndIf
+ EndIf
+ EndIf
+ Return False
+EndFunc
+
+Func checkMatchRightRight($coloredMap,$x,$y)
+ if $x < 4 Then
+ if $coloredMap[$y][$x] == $coloredMap[$y][$x+3] Then
+ if $coloredMap[$y][$x] == $coloredMap[$y][$x+2] Then
+ ConsoleWrite(@LF )
+ ConsoleWrite(" Row Match 3 right right")
+ MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +1) * 37) - 11 )
+ MouseClick ( "left" ,$coord[0] + 18 +( ($x + 1) * 37), $coord[1] + ( ($y +1) * 37) - 11 )
+ Return True
+;~ Else
+;~ ConsoleWrite($coloredMap[$y+1][$x+1]& " , ")
+;~ ConsoleWrite($coloredMap[$y+1][$x+2]& " , ")
+ EndIf
+ EndIf
+ EndIf
+ Return False
+EndFunc
+
+Func checkMatchRightMiddle($coloredMap,$x,$y)
+ if $y > 0 And $x < 6 And $y < 6 Then
+ if $coloredMap[$y][$x] == $coloredMap[$y-1][$x+1] And $coloredMap[$y][$x] == $coloredMap[$y+1][$x+1] Then
+ ConsoleWrite(@LF )
+ ConsoleWrite(" Row Match 3 right middle")
+ ;Click the current cell
+ MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +1) * 37) - 11 )
+ ;Click 1 up
+ MouseClick ( "left" ,$coord[0] + 18 +( ($x + 1) * 37), $coord[1] + ( ($y +1) * 37) - 11 )
+ Return True
+ EndIf
+ EndIf
+ Return False
+EndFunc
+
+Func checkMatchBottomMiddle($coloredMap,$x,$y)
+ if $x < 6 And $x > 0 And $y <= 6 Then
+ if $coloredMap[$y][$x] == $coloredMap[$y+1][$x+1] And $coloredMap[$y][$x] == $coloredMap[$y+1][$x-1] Then
+ ConsoleWrite(@LF )
+ ConsoleWrite(" Row Match 3 right middle")
+ ;Click the current cell
+ MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +1) * 37) - 11 )
+ ;Click 1 to the right
+ MouseClick ( "left" ,$coord[0] + 18 +( ($x) * 37), $coord[1] + ( ($y +2) * 37) - 11 )
+ Return True
+ EndIf
+ EndIf
+ Return False
+EndFunc
+
+
+Func checkMatchUpUp($coloredMap,$x,$y)
+ if $y > 2 Then
+ if $coloredMap[$y][$x] == $coloredMap[$y-3][$x] And $coloredMap[$y][$x] == $coloredMap[$y-2][$x] Then
+ ConsoleWrite(@LF )
+ ConsoleWrite(" Row Match 3 right middle")
+ ;Click the current cell
+ MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +1) * 37) - 11 )
+ ;Click 1 to the right
+ MouseClick ( "left" ,$coord[0] + 18 +( ($x) * 37), $coord[1] + ( ($y) * 37) - 11 )
+ Return True
+ EndIf
+ EndIf
+ Return False
+EndFunc
+
+
Func solveSingleMatch($crd)
Local $coloredMap[8][8]
for $i = 0 To UBound($crd) - 1
For $x = 0 To 7 Step 1
Switch $crd[$i][$x]
Case 16775956,16776960
$coloredMap[$i][$x] = "Yellow"
- ;~ ConsoleWrite("Yellow , ")
Case 16206352,16471568 ; we also match 15* as red in most cases
$coloredMap[$i][$x] = "Red"
- ;~ ConsoleWrite("Red , ")
Case 16777215,16514043
$coloredMap[$i][$x] = "Silver"
- ;~ ConsoleWrite("Silver , ")
Case 12749289,12885488,11902199 ,13021688,12029936,12157930
$coloredMap[$i][$x] = "Purple"
- ;~ ConsoleWrite("Purple , ")
Case 5420321,4303909
$coloredMap[$i][$x] = "Green"
- ;~ ConsoleWrite("Green , ")
Case 16675594
$coloredMap[$i][$x] = "Orange"
- ;~ ConsoleWrite("Orange , ")
Case 6220025,5565436,8249328,5892858,4911103,6353407,6547447,7921905,6874614,7202036
$coloredMap[$i][$x] = "Blue"
- ;~ ConsoleWrite("Blue , ")
Case Else
;If the color code is not matched above then we do a rough check
;This may be wrong so we mark with a * (note this has yet to match a wrong color)
$checker = StringLeft(StringFormat("%i",$crd[$i][$x]),2)
Switch $checker
Case "16"
$coloredMap[$i][$x] = "Orange"
- ;~ ConsoleWrite("*Orange* , ")
Case "15"
$coloredMap[$i][$x] = "Red"
- ;~ ConsoleWrite("*Red* , ")
Case "52","75"
$coloredMap[$i][$x] = "Blue"
- ;~ ConsoleWrite("*Blue* , ")
Case Else
$coloredMap[$i][$x] = $checker
- ;~ ConsoleWrite($checker &", ")
EndSwitch
EndSwitch
Next
- ;~ ConsoleWrite(@LF )
Next
for $y = 0 To 7
For $x = 0 To 7 Step 1
+ ;Stop the loops if any of the functions return true
+ if checkMatchDownRight($coloredMap,$x,$y) Then
+ ExitLoop(2)
+ EndIf
+ if checkMatchRightRight($coloredMap,$x,$y) Then
+ ExitLoop(2)
+ EndIf
+ if checkMatchRightMiddle($coloredMap,$x,$y) Then
+ ExitLoop(2)
+ EndIf
+ if checkMatchUpUp($coloredMap,$x,$y) Then
+ ExitLoop(2)
+ EndIf
+ if checkMatchBottomMiddle($coloredMap,$x,$y) Then
+ ExitLoop(2)
+ EndIf
+
if $y < 7 Then
ConsoleWrite($coloredMap[$y][$x] & " , ")
;Search for and item 1 down and 2 to the right
if $x < 6 Then
- if $coloredMap[$y][$x] == $coloredMap[$y+1][$x+2] Then
- if $coloredMap[$y+1][$x+1] == $coloredMap[$y][$x] Then
- ConsoleWrite(@LF )
- ConsoleWrite(" Row Match 3 down right")
- MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +1) * 37) - 11 )
- MouseClick ( "left" ,$coord[0] + 18 +( $x * 37), $coord[1] + ( ($y +2) * 37) - 11 )
- sleep(5)
- ExitLoop(2)
- ConsoleWrite(@LF )
- Else
- ConsoleWrite($coloredMap[$y+1][$x+1]& " , ")
- ConsoleWrite($coloredMap[$y+1][$x+2]& " , ")
- EndIf
- EndIf
-
+ if $y < 5 Then
+ if $coloredMap[$y][$x] == $coloredMap[$y+3][$x] Then
+ if $coloredMap[$y][$x] == $coloredMap[$y+2][$x] Then
+ ConsoleWrite(@LF )
+ ConsoleWrite(" Row Match 3 down down")
+ MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +1) * 37) - 11 )
+ MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +2) * 37) - 11 )
+ sleep(5)
+ ExitLoop(2)
+ ConsoleWrite(@LF )
+ EndIf
+ Else
+ ;We need to check 3 down when moving blocks down
+ ;ConsoleWrite($coloredMap[$y+1][$x]& " , ")
+ ConsoleWrite($coloredMap[$y+2][$x]& " , ")
+ ConsoleWrite($coloredMap[$y+3][$x]& " , ")
+ EndIf
+ EndIf
EndIf
;Search for and item 1 down and 2 to the left
if $x > 2 Then
@@ -144,7 +238,7 @@ Func solveSingleMatch($crd)
ConsoleWrite(@LF )
ConsoleWrite(" Row Match 3 up")
MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y +1) * 37) - 11 )
- MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( ($y) * 37) - 11 )
+ MouseClick ( "left" ,$coord[0] + 18 +( $x* 37), $coord[1] + ( $y * 37) - 11 )
ExitLoop(2)
ConsoleWrite(@LF )
Else
@@ -172,6 +266,6 @@ While $count <= 10
$uncoloredMap = buildColorMap()
solveSingleMatch($uncoloredMap)
ConsoleWrite("Sleeping")
- Sleep(10000)
+;~ Sleep(5000)
WEnd
;~ ConsoleWrite($coloredMap[0][0])

0 comments on commit 8a78285

Please sign in to comment.