Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # To change this template, choose Tools | Templates
- # and open the template in the editor.
- module SeniorSeminar
- class InvalidPlayException < Exception ; end
- class InvalidPieceException < Exception ; end
- class Board
- attr_reader :dimensions, :turn
- def initialize dimen = 6, players = 2
- @dimensions = [dimen, dimen]
- @field = [nil]*dimen
- @field.map! do |row|
- row = [nil]*dimen
- end
- @turn = 0
- @last_turn = nil
- @pieces = [:b, :w, :r, :g, :y, :c][0,players]
- end
- ...
- def rotate x, y, direction=:right
- times = direction_to_turns direction
- x,y = self.get_quadrant_coordinates x,y
- len = @dimensions[0] / 2
- times.times do
- @field.map.class #=> Array
- @field.map!.class #=>Enumerator
- # ^ this is the opposite of what the doc says
- @field = @field.map!.with_index do |line, i|
- line.map!.with_index do |elem, j|
- (x..(x+len))===i && (y..(y+len))===j ?
- @field[x+y+len-j-1][y+i-x] : elem
- end
- end
- end
- end
- ...
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement