Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/1200/screen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"""
Grid positions for 1440p:
(1740, 134) to (2508, 902)
Grid positions for 1920x1200 (windowed):
(1237, 112)
grid_size 640
gem_size 80
"""

class Configuration:
Expand All @@ -20,15 +24,19 @@ class Configuration:

tolerance = 4 # RGB tolerance range for gem color detection
skip = 5 # Percentage (100 / skip %) of pixels averaged to determine gem color (higher = slower, but more accurate)

unknown_threshold = 48 # Max number of unknown gems allowed before converting board
chain_delay = 0.25 # Number of seconds to delay for each chain level above one (1.36 for update one chain)
one_by_one = False # Make one turn before update board (1.36 and true for FOR THE SWARM)
# Not implemented
look_ahead_count = 3 # Look ahead X number of moves to find the best move
chain_delay = 0.25 # Number of seconds to delay for each chain level above one
powerset_limit = 5 # Maximum number of moves we can calculate powerset for without hindering performance

enabled = False # Runtime flag -- run the bot algorithm?
debug = False # Runtime flag -- show debug output
benchmark = False # Runtime flag -- show performance data
calibrating = False # Runtime flag -- show average RGB values when converting image to map
show_turns = True # Show moves in log


# Color mapping table -- maps skip -> ([color -> average rgb value])
Expand Down
3 changes: 2 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def enable_toggle():
Configuration.enabled = True

# Move mouse to top left corner to stop the bot
elif x < 5 and y == 0:
elif x < 10 and y < 10:
print_debug("Bot Disabled")
Configuration.enabled = False

Expand Down Expand Up @@ -84,6 +84,7 @@ def main(args):
scan_time = benchmark.time("scan")
benchmark.start("decision")
move_set = Strategy(board).decide()

decide_time = benchmark.time("decision")
move_set.make()
total_time = benchmark.time("main")
Expand Down
60 changes: 60 additions & 0 deletions src/resolution/1200/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from definitions import *

"""
Grid positions for 1440p:
(1740, 134) to (2508, 902)
"""

class Configuration:
screen_width = 1920 # Width of computer screen
screen_height = 1200 # Height of computer screen

offset_x = 1237 # X offset of grid
offset_y = 112 # Y offset of grid
grid_size = 640 # Size of grid (square)
gem_size = 80 # Size of gem (square)
grid_length = 8 # Number of gems from top-bottom or left-right

idle_x = 20 # X offset for idle position
idle_y = 20 # Y offset for idle position

tolerance = 4 # RGB tolerance range for gem color detection
skip = 5 # Percentage (100 / skip %) of pixels averaged to determine gem color (higher = slower, but more accurate)
unknown_threshold = 2 # Max number of unknown gems allowed before converting board

chain_delay = 0.25 # Number of seconds to delay for each chain level above one (1.36 for update one chain)
one_by_one = False # Make one turn before update board (1.36 and true for FOR THE SWARM)

# Not implemented
look_ahead_count = 20 # Look ahead X number of moves to find the best move
powerset_limit = 20 # Maximum number of moves we can calculate powerset for without hindering performance

enabled = False # Runtime flag -- run the bot algorithm?
debug = False # Runtime flag -- show debug output
benchmark = False # Runtime flag -- show performance data
calibrating = False # Runtime flag -- show average RGB values when converting image to map
show_turns = True # Show moves in log


# Color mapping table -- maps skip -> ([color -> average rgb value])
color_table = {
5 : {
Color.white : (15, 15, 14),
Color.red : (24, 10, 6),
Color.blue : (13, 28, 34),
Color.purple : (15, 8, 15),
Color.green : (15, 26, 8),
Color.yellow : (23, 22, 10)
}
}


# Points mapping table -- maps match_length -> points
points_table = {
3 : 30,
4 : 60,
5 : 120,
6 : 240,
7: 480,
8: 960
}
22 changes: 19 additions & 3 deletions src/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,33 @@ def decide(self):

# Calculate a score for each move based on a calculation of the three metrics
for move_id, info in move_info.iteritems():
move_score[move_id] = info[0] + (info[2] * 5) # points_gained + (num_moves_created * 5)

#move_score[move_id] = info[0] + (info[2] * 5) # points_gained + (num_moves_created * 5)
# 2 gj
# 3 fantastic
# 4 hardcore
# 5 masterful
# 6 for the swarm
if info[1] >= 4:
move_score[move_id] = info[1] * 1000
else:
move_score[move_id] = move_dictionary[move_id].point.y + (info[2] * 5)

# Order the moves from best move to worst move (based on score) and return them as a MoveSet with delays added
moves = []
total_points = 0
highest_chain = 0
move_ids = []

for move_id in sorted(move_score, key = move_score.get, reverse = True):
move_ids.append(move_id)
moves.append(move_dictionary[move_id])
total_points += move_info[move_id][0]
highest_chain = move_info[move_id][1] if move_info[move_id][1] > highest_chain else highest_chain
if Configuration.one_by_one:
break

if len(move_ids) > 0 and Configuration.show_turns:
for move_id in move_ids:
print_debug("highest_chain: "+str(move_info[move_id][1])+" "+str(move_dictionary[move_id].point.x)+"x"+str(move_dictionary[move_id].point.y)+" = "+str(move_info[move_id][0]) +" ("+str(move_score[move_id])+")")

return MoveSet(moves, total_points, 0)
return MoveSet(moves, total_points, highest_chain * Configuration.chain_delay)