-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathai_black.rb
54 lines (42 loc) · 1.16 KB
/
ai_black.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require "xmlrpc/server"
require "socket"
s = XMLRPC::Server.new(ARGV[0])
MAX_NUMBER = 16000
class MyAlggago
def calculate(positions)
#Codes here
my_position = positions[0]
your_position = positions[1]
current_stone_number = 0
index = 0
min_length = MAX_NUMBER
x_length = MAX_NUMBER
y_length = MAX_NUMBER
my_position.each do |my|
your_position.each do |your|
x_distance = (my[0] - your[0]).abs
y_distance = (my[1] - your[1]).abs
current_distance = Math.sqrt(x_distance * x_distance + y_distance * y_distance)
if min_length > current_distance
current_stone_number = index
min_length = current_distance
x_length = your[0] - my[0]
y_length = your[1] - my[1]
end
end
index = index + 1
end
#Return values
message = positions.size
stone_number = current_stone_number
stone_x_strength = x_length * 5
stone_y_strength = y_length * 5
return [stone_number, stone_x_strength, stone_y_strength, message]
#Codes end
end
def get_name
"MY AI!!!"
end
end
s.add_handler("alggago", MyAlggago.new)
s.serve