|
|
@@ -10,6 +10,9 @@ config.transaction do
|
|
|
$lookahead = config["lookahead"].to_i
|
|
|
end
|
|
|
|
|
|
+$dirs = Queue.new
|
|
|
+$ticks = 0
|
|
|
+
|
|
|
def connect(host, port)
|
|
|
$sock = TCPSocket.new(host, port)
|
|
|
# join($name,$password)
|
|
|
@@ -29,7 +32,7 @@ def parse(message)
|
|
|
puts "error occured " + parts[1]
|
|
|
|
|
|
when "game"
|
|
|
- puts message
|
|
|
+ puts "#{Time.now.strftime('%M%S%L')}: #{message}"
|
|
|
$gameW = parts[1].to_i
|
|
|
$gameH = parts[2].to_i
|
|
|
$id = parts[3].to_i
|
|
|
@@ -43,18 +46,20 @@ def parse(message)
|
|
|
$myY = parts[3].to_i
|
|
|
end
|
|
|
when "tick"
|
|
|
- puts message
|
|
|
+ puts "#{Time.now.strftime('%M%S%L')}: #{message}"
|
|
|
+ puts "tick took: #{Time.now.strftime('%M%S%L') - $lasttick}"
|
|
|
+ $lasttick = Time.now.strftime('%M%S%L')
|
|
|
decide()
|
|
|
when "die"
|
|
|
- puts message
|
|
|
+ puts "#{Time.now.strftime('%M%S%L')}: #{message}"
|
|
|
parts.drop(1).each { |player| cleanup(player) }
|
|
|
when "message"
|
|
|
- puts message
|
|
|
+ puts "#{Time.now.strftime('%M%S%L')}: #{message}"
|
|
|
when "win", "lose"
|
|
|
- puts message
|
|
|
+ puts "#{Time.now.strftime('%M%S%L')}: #{message}"
|
|
|
reset()
|
|
|
when "motd"
|
|
|
- puts message
|
|
|
+ puts "#{Time.now.strftime('%M%S%L')}: #{message}"
|
|
|
join($name, $password)
|
|
|
end
|
|
|
|
|
|
@@ -176,8 +181,26 @@ def check_area(direction)
|
|
|
end
|
|
|
|
|
|
def decide()
|
|
|
+ $ticks = $ticks + 1
|
|
|
|
|
|
lastdirection = $direction
|
|
|
+
|
|
|
+
|
|
|
+ if $dirs.length > 0
|
|
|
+ puts "in queue"
|
|
|
+ $direction = $dirs.pop
|
|
|
+
|
|
|
+ if check_front > -1 && !$dead.include?(check_front)
|
|
|
+ #chat("You crossed my Plans!")
|
|
|
+ $direction = lastdirection
|
|
|
+ $dirs.clear()
|
|
|
+ else
|
|
|
+ send("move", $direction)
|
|
|
+ return
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
# check area front
|
|
|
front = check_area("front")
|
|
|
# check area left
|
|
|
@@ -185,41 +208,51 @@ def decide()
|
|
|
# check area right
|
|
|
right = check_area("right")
|
|
|
|
|
|
- if left > front && left > right
|
|
|
- puts "#{left} > #{front} && #{left} > #{right} -> left"
|
|
|
- $direction = turn_direction("left")
|
|
|
- else
|
|
|
- if right > front && right > left
|
|
|
- puts "#{right} > #{front} && #{right} > #{left} -> right"
|
|
|
- $direction = turn_direction("right")
|
|
|
+ if($ticks < 30)
|
|
|
+
|
|
|
+ if left > front && left > right
|
|
|
+ puts "#{left} > #{front} && #{left} > #{right} -> left"
|
|
|
+ $direction = turn_direction("left")
|
|
|
+ $dirs << "left"
|
|
|
+ puts "qued left"
|
|
|
+ else
|
|
|
+ if right > front && right > left
|
|
|
+ puts "#{right} > #{front} && #{right} > #{left} -> right"
|
|
|
+ $direction = turn_direction("right")
|
|
|
+ $dirs << "right"
|
|
|
+ puts "qued right"
|
|
|
+ end
|
|
|
end
|
|
|
- end
|
|
|
- # if check_front > -1 && !$dead.include?(check_front) || check_area("front") < 10
|
|
|
- #
|
|
|
- # if left > right
|
|
|
- # $direction = turn_direction("left")
|
|
|
- # else
|
|
|
- # if left == right
|
|
|
- # case $lastturn
|
|
|
- # when "left"
|
|
|
- # $direction = turn_direction("right")
|
|
|
- # $lastturn = "right"
|
|
|
- # when "right"
|
|
|
- # $direction = turn_direction("left")
|
|
|
- # $lastturn = "left"
|
|
|
- # end
|
|
|
- # else
|
|
|
- # $direction = turn_direction("right")
|
|
|
- # end
|
|
|
- # end
|
|
|
- #
|
|
|
- # puts "#{left} > #{right}: turned #{$direction}"
|
|
|
- # end
|
|
|
- # $direction = new_direction()
|
|
|
- # if $tries > 4
|
|
|
- # break
|
|
|
- # end
|
|
|
- # end
|
|
|
+ else
|
|
|
+
|
|
|
+ if check_front > -1 && !$dead.include?(check_front) || check_area("front") < 10
|
|
|
+
|
|
|
+ if left > right
|
|
|
+ $direction = turn_direction("left")
|
|
|
+ else
|
|
|
+ if left == right
|
|
|
+ case $lastturn
|
|
|
+ when "left"
|
|
|
+ $direction = turn_direction("right")
|
|
|
+ $lastturn = "right"
|
|
|
+ $dirs << "right"
|
|
|
+ when "right"
|
|
|
+ $direction = turn_direction("left")
|
|
|
+ $lastturn = "left"
|
|
|
+ $dirs << "left"
|
|
|
+ end
|
|
|
+ else
|
|
|
+ $direction = turn_direction("right")
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ puts "#{left} > #{right}: turned #{$direction}"
|
|
|
+ end
|
|
|
+ end
|
|
|
+ #$direction = new_direction()
|
|
|
+ #if $tries > 4
|
|
|
+ # break
|
|
|
+ #end
|
|
|
|
|
|
if check_front > -1 && !$dead.include?(check_front)
|
|
|
chat("To honor the Fallen")
|
|
|
@@ -246,7 +279,7 @@ def send(msg, *param)
|
|
|
snd = msg
|
|
|
end
|
|
|
$sock.puts(snd)
|
|
|
- puts(snd)
|
|
|
+ puts("#{Time.now.strftime('%M%S%L')}: #{snd}")
|
|
|
end
|
|
|
|
|
|
def initmap()
|
|
|
@@ -281,4 +314,4 @@ def fill(x, y, depth)
|
|
|
return sum
|
|
|
end
|
|
|
|
|
|
-connect($host, $port)
|
|
|
+connect($host, $port)
|