Class Hex
In: lib/core/board.rb
Parent: Object

Node numbers

   5---------0
   /          #   /            # 4/             \1
 \             /
  \           /
   \         /
   3---------2

Methods

Attributes

card_type  [RW] 
coords  [RW] 
edges  [RW] 
has_bandit  [RW] 
nodes  [RW] 
number  [RW] 

Public Class methods

[Source]

# File lib/core/board.rb, line 68
  def initialize(card, number, has_bandit=false)
    @card_type = card
    @number = number
    @has_bandit = has_bandit
    @nodes = []
    @edges = []
  end

Public Instance methods

[Source]

# File lib/core/board.rb, line 80
  def connect_hex(edgeIndex, hex2)
    edgeIndex2 = (edgeIndex-1)%6
    if hex2
      i2 = (edgeIndex + 3) % 6
      @edges[edgeIndex].nodes = [] if @edges[edgeIndex]
      hex2.edges[i2].nodes = [] if hex2.edges[i2]

      edge = @edges[edgeIndex]
      edge = hex2.edges[i2] if hex2.edges[i2]
      edge = Edge.new if not edge
      hex2.edges[i2] = edge
      tempNodes = connect_to_nodes(edge, edgeIndex, i2, hex2)
    else
      edge = Edge.new
      tempNodes = connect_to_nodes(edge, edgeIndex, i2, nil)
      edge.nodes = tempNodes
    end
    @edges[edgeIndex] = edge
    edge.coords = @coords + [edgeIndex]

    tempNodes.each_with_index{|n,i|
      tempEdgeIndex = i==0 ? edgeIndex : edgeIndex2
      n.coords = @coords + [tempEdgeIndex]
      n.edges.uniq!
      @nodes[tempEdgeIndex] = n
      n.hexes << self
      n.hexes.uniq!
    }
  end

helper for connectHex

[Source]

# File lib/core/board.rb, line 111
  def connect_to_nodes(edge, edgeIndex, i2, hex2 = nil)
    n1 = @nodes[edgeIndex]
    n2 = @nodes[(edgeIndex-1)%6]
    n1 = hex2.nodes[(i2-1)%6] if not n1 and hex2
    n2 = hex2.nodes[i2] if not n2 and hex2
    n1 = Node.new if not n1
    n2 = Node.new if not n2
    n1.edges << edge
    n2.edges << edge
    
    if hex2
      hex2.nodes[i2] = n2
      hex2.nodes[(i2-1)%6] = n1
      edge.nodes = [n1, n2]
    end
    [n1,n2]
  end

[Source]

# File lib/core/board.rb, line 78
  def get_2_cards() [@card_type, @card_type] end

[Source]

# File lib/core/board.rb, line 76
  def get_card() @card_type end

gets the cartesian coordinatess of the rightmost point of this hex

[Source]

# File lib/core/board.rb, line 134
  def get_cartesian
    x,y = @coords
    [x, y+((x%2)/2.0)]
  end

get the probablity for this hex’s number

[Source]

# File lib/core/board.rb, line 131
  def get_prob() @@dice_probs[@number] end

[Source]

# File lib/core/board.rb, line 139
  def to_s() "Resource tile: " + @card_type.to_s end

[Validate]