 
   get_hex_xy: (a,b) ->
     x = a*14 + @dx
-    y = (2*b + a%2)*10 + @dy
+    if a%2 != 0 then odd = 1 else odd = 0
+    y = (2*b + odd)*10 + @dy
     xy = [x,y]
     return xy
 
 
   fill_hex_ab: (a,b,c_no) ->
+    alert("fill_hex_ab: "+a+","+b+"  "+c_no) if c_no == 1
     xy = @get_hex_xy(a,b)
     @fill_hex_xy(xy[0],xy[1],c_no)
 


class PuzzleGridModel

    # TODO Since this is the only method left in this class,
    #      what is the future of this class?
  get_hex: (x,y) ->
    hex = [0,0]
    in_bounds = true
    aa = Math.floor((x-12)/14)-7
    bb = Math.floor((y-9*(aa%2)+2.5)/20)-1
    in_bounds = false if @in_range(aa,bb) == false

    corner = @get_xy(aa,bb)
    ctr_x = corner[0]+9
    ctr_y = corner[1]+10
    dx = Math.abs(x-ctr_x)
    dy = Math.abs(y-ctr_y)
    r2 = dx*dx+dy*dy
    in_bounds = false if r2>67 #(if radius > 8.2)

    hex = [aa,bb] if (in_bounds == true)
    return hex


  get_xy: (a,b) -> 
    if @in_range(a,b)
      x = 100 + 14*a + (a%2)/2 + @t_dx
      y = 30 + 20*b + (a%2)*10 + @t_dy
      xy = [x,y]
    else
      xy = [0,0]
    return xy


  in_range: (a,b) ->
    a = 0 if not a?
    b = 0 if not b?
    ok = true
    ok = false if a<1 || a>24
    ok = false if b<1 || b>10
    ok = false if b == 10 && a%2 == 1
    return ok




    pc = Math.floor(16*Math.random())
    @piece.construct_piece(pieces[pc])

    @pixel_test = new PixelHexTester(this)
    @pixel_test.adjusted_hex_quick_mark()



