class AresHackathon::Field
Attributes
size_x[R]
size_y[R]
Public Class Methods
new(sx, sy, field)
click to toggle source
# File lib/ares-hackathon/field.rb, line 4 def initialize(sx, sy, field) @size_x = sx @size_y = sy @field = field end
read_from_socket(conn)
click to toggle source
# File lib/ares-hackathon/field.rb, line 10 def self.read_from_socket(conn) sizes = conn.recv(2) sx = sizes[0].ord sy = sizes[1].ord field = [] for x in 0..(sx-1) field[x] = [] end for y in 0..(sy-1) buffer = conn.recv(2*sx) for x in 0..(sx-1) field[x][y] = AresHackathon::Cell.new x, y, buffer[2*x].ord, buffer[2*x+1].ord end end return AresHackathon::Field.new sx, sy, field end
Public Instance Methods
cell(x,y)
click to toggle source
# File lib/ares-hackathon/field.rb, line 29 def cell(x,y) return @field[x][y] end
has_lost(p)
click to toggle source
# File lib/ares-hackathon/field.rb, line 33 def has_lost(p) @field.each do |row| row.each do |cell| return false if cell.owner == p end end return true end
has_win(p)
click to toggle source
# File lib/ares-hackathon/field.rb, line 42 def has_win(p) @field.each do |row| row.each do |cell| return false if cell.owner != p && cell.owner != 0 end end return true end
owned_by(player)
click to toggle source
# File lib/ares-hackathon/field.rb, line 51 def owned_by(player) res = @field.map do |line| line.select do |cell| cell.owner == player end end return res.flatten end