Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.07 KB | None | 0 0
  1. # To change this template, choose Tools | Templates
  2. # and open the template in the editor.
  3.  
  4. module SeniorSeminar
  5.   class InvalidPlayException < Exception ; end
  6.   class InvalidPieceException < Exception ; end
  7.   class Board
  8.     attr_reader :dimensions, :turn
  9.    
  10.     def initialize dimen = 6, players = 2
  11.       @dimensions = [dimen, dimen]
  12.       @field = [nil]*dimen
  13.       @field.map! do |row|
  14.         row = [nil]*dimen
  15.       end
  16.       @turn = 0
  17.       @last_turn = nil
  18.       @pieces = [:b, :w, :r, :g, :y, :c][0,players]
  19.     end
  20.     ...
  21.     def rotate x, y, direction=:right
  22.       times = direction_to_turns direction
  23.       x,y = self.get_quadrant_coordinates x,y
  24.       len = @dimensions[0] / 2
  25.       times.times do
  26.      @field.map.class #=> Array
  27.      @field.map!.class #=>Enumerator
  28.         # ^ this is the opposite of what the doc says
  29.         @field = @field.map!.with_index do |line, i|
  30.           line.map!.with_index do |elem, j|
  31.             (x..(x+len))===i && (y..(y+len))===j ?
  32.               @field[x+y+len-j-1][y+i-x] : elem
  33.           end
  34.         end
  35.       end
  36.     end
  37.     ...
  38.   end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement