|
@@ -7,6 +7,7 @@ config.transaction do
|
|
|
$password = config["password"]
|
|
$password = config["password"]
|
|
|
$host = config["host"]
|
|
$host = config["host"]
|
|
|
$port = config["port"]
|
|
$port = config["port"]
|
|
|
|
|
+ $lookahead = config["lookahead"].to_i
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def connect(host, port)
|
|
def connect(host, port)
|
|
@@ -64,6 +65,7 @@ def cleanup(player)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
$tries = 0
|
|
$tries = 0
|
|
|
|
|
+
|
|
|
def check_front
|
|
def check_front
|
|
|
|
|
|
|
|
# puts "#{$direction} at #{$myX},#{$myY} - try: #{$tries}"
|
|
# puts "#{$direction} at #{$myX},#{$myY} - try: #{$tries}"
|
|
@@ -92,6 +94,31 @@ def overflow(new, max)
|
|
|
new
|
|
new
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+def turned_position(turn_direction)
|
|
|
|
|
+ dir = 0
|
|
|
|
|
+ front = 0
|
|
|
|
|
+ case turn_direction
|
|
|
|
|
+ when "left"
|
|
|
|
|
+ dir = -1
|
|
|
|
|
+ when "right"
|
|
|
|
|
+ dir = 1
|
|
|
|
|
+ when "front"
|
|
|
|
|
+ front = 1
|
|
|
|
|
+ dir = 0
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ case $direction
|
|
|
|
|
+ when "up"
|
|
|
|
|
+ return overflow($myX + dir, $gameW), overflow($myY - front, $gameH)
|
|
|
|
|
+ when "down"
|
|
|
|
|
+ return overflow($myX - dir, $gameW), overflow($myY + front, $gameH)
|
|
|
|
|
+ when "left"
|
|
|
|
|
+ return overflow($myX - front, $gameW), overflow($myY - dir, $gameH)
|
|
|
|
|
+ when "right"
|
|
|
|
|
+ return overflow($myX + front, $gameW), overflow($myY + dir, $gameH)
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
def new_direction
|
|
def new_direction
|
|
|
case $direction
|
|
case $direction
|
|
|
when "up"
|
|
when "up"
|
|
@@ -105,19 +132,72 @@ def new_direction
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+def turn_direction(dir)
|
|
|
|
|
+ case $direction
|
|
|
|
|
+ when "up"
|
|
|
|
|
+ if dir == "right"
|
|
|
|
|
+ "right"
|
|
|
|
|
+ else
|
|
|
|
|
+ "left"
|
|
|
|
|
+ end
|
|
|
|
|
+ when "down"
|
|
|
|
|
+ if dir == "right"
|
|
|
|
|
+ "left"
|
|
|
|
|
+ else
|
|
|
|
|
+ "right"
|
|
|
|
|
+ end
|
|
|
|
|
+ when "left"
|
|
|
|
|
+ if dir == "right"
|
|
|
|
|
+ "up"
|
|
|
|
|
+ else
|
|
|
|
|
+ "down"
|
|
|
|
|
+ end
|
|
|
|
|
+ when "right"
|
|
|
|
|
+ if dir == "right"
|
|
|
|
|
+ "down"
|
|
|
|
|
+ else
|
|
|
|
|
+ "up"
|
|
|
|
|
+ end
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+def check_area(direction)
|
|
|
|
|
+ $fillmap = Array.new($gameH) { Array.new($gameW) { -1 } }
|
|
|
|
|
+
|
|
|
|
|
+ (0...$gameH).each do |i|
|
|
|
|
|
+ (0...$gameW).each { |j| $fillmap[i][j] = $map[i][j] }
|
|
|
|
|
+ end
|
|
|
|
|
+ x, y = turned_position(direction)
|
|
|
|
|
+ fill(x, y, 0)
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
def decide()
|
|
def decide()
|
|
|
|
|
|
|
|
- $tries = 0
|
|
|
|
|
- while check_front > -1 && !$dead.include?(check_front)
|
|
|
|
|
- $direction = new_direction()
|
|
|
|
|
- if $tries > 4
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ # check area left
|
|
|
|
|
+ left = check_area("left")
|
|
|
|
|
+ # check area right
|
|
|
|
|
+ right = check_area("right")
|
|
|
|
|
+
|
|
|
|
|
+ if check_front > -1 && !$dead.include?(check_front) || check_area("front") < 10
|
|
|
|
|
+ if left > right
|
|
|
|
|
+ $direction = turn_direction("left")
|
|
|
|
|
+ else
|
|
|
|
|
+ $direction = turn_direction("right")
|
|
|
end
|
|
end
|
|
|
|
|
+ puts "#{left} > #{right}: turned #{$direction}"
|
|
|
end
|
|
end
|
|
|
|
|
+ # $direction = new_direction()
|
|
|
|
|
+ # if $tries > 4
|
|
|
|
|
+ # break
|
|
|
|
|
+ # end
|
|
|
|
|
+ # end
|
|
|
|
|
|
|
|
send("move", $direction)
|
|
send("move", $direction)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+# $tries = 0
|
|
|
|
|
+# while check_front > -1 && !$dead.include?(check_front)
|
|
|
|
|
+
|
|
|
def chat(message)
|
|
def chat(message)
|
|
|
send("chat", message)
|
|
send("chat", message)
|
|
|
end
|
|
end
|
|
@@ -143,7 +223,27 @@ def initmap()
|
|
|
chat("Rock and Stone!")
|
|
chat("Rock and Stone!")
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+def fill(x, y, depth)
|
|
|
|
|
+ x = overflow(x, $gameW)
|
|
|
|
|
+ y = overflow(y, $gameH)
|
|
|
|
|
|
|
|
|
|
+ tile = $fillmap[x][y]
|
|
|
|
|
|
|
|
-connect($host, $port)
|
|
|
|
|
|
|
+ if depth > $lookahead
|
|
|
|
|
+ return 0
|
|
|
|
|
+ end
|
|
|
|
|
+ if tile > -1 && !$dead.include?(tile)
|
|
|
|
|
+ return 0
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ $fillmap[x][y] = 42 # mark as visited
|
|
|
|
|
+ sum = 1
|
|
|
|
|
+ sum += fill(x - 1, y, depth + 1)
|
|
|
|
|
+ sum += fill(x + 1, y, depth + 1)
|
|
|
|
|
+ sum += fill(x, y - 1, depth + 1)
|
|
|
|
|
+ sum += fill(x, y + 1, depth + 1)
|
|
|
|
|
+
|
|
|
|
|
+ return sum
|
|
|
|
|
+end
|
|
|
|
|
|
|
|
|
|
+connect($host, $port)
|