| 1 | package Games::Go::Cinderblock::Rulemap::Graph; | ||
| 2 | use Moose; | ||
| 3 | extends 'Games::Go::Cinderblock::Rulemap'; | ||
| 4 | |||
| 5 | #TODO: perhaps subclasses for polyhedra, streetmaps, lattice, & custom | ||
| 6 | # nodes are represented as an integer, | ||
| 7 | |||
| 8 | |||
| 9 | sub all_node_coordinates{ #only for graph | ||
| 10 | my $self = shift; | ||
| 11 | return $self->{nodes_co}; | ||
| 12 | } | ||
| 13 | sub node_adjacency_list{ #only for graph | ||
| 14 | my $self = shift; | ||
| 15 | return $self->{adjacent}; | ||
| 16 | } | ||
| 17 | |||
| 18 | |||
| 19 | sub all_nodes{ | ||
| 20 | my $self = shift; | ||
| 21 | my $num_nodes = scalar @{$self->{nodes}}; | ||
| 22 | return (0..$num_nodes-1); | ||
| 23 | } | ||
| 24 | sub graph_node_liberties{ | ||
| 25 | my ($self, $node) = @_; | ||
| 26 | return @{ $self->{adjacent_nodes}{$node} }; | ||
| 27 | } | ||
| 28 | sub graph_stone_at_node{ | ||
| 29 | my ($self, $board, $node) = @_; | ||
| 30 | return $board->[$node] | ||
| 31 | } | ||
| 32 | |||
| 33 | #going by the picture in wikipedia.. lol, not used | ||
| 34 | #coordinates from 0 to 1 | ||
| 35 | sub build_20_fullerene{ | ||
| 36 | my @nodes; #really has planar coordinates (x,y) | ||
| 37 | my @edges; | ||
| 38 | my @ring; #a 5-gon | ||
| 39 | for (0..4){ | ||
| 40 | push @ring, [cos (6.28*$_/5), sin (6.28*$_/5)] | ||
| 41 | } | ||
| 42 | push @nodes, @ring; | ||
| 43 | for my $n (0..4){ #scale & push | ||
| 44 | my @node = @{$nodes[$n]}; | ||
| 45 | $node[0] *= 1.5; | ||
| 46 | $node[1] *= 1.5; | ||
| 47 | push @nodes, \@node; | ||
| 48 | push @edges, [$n,$n+5]; | ||
| 49 | } | ||
| 50 | for my $n (5..9){ #flip, scale & push | ||
| 51 | my @node = @{$nodes[$n]}; | ||
| 52 | $node[0] *= -1.3; | ||
| 53 | $node[1] *= -1.3; | ||
| 54 | push @nodes, \@node; | ||
| 55 | push @edges, [5+($n+2)%5,$n+5]; | ||
| 56 | push @edges, [5+($n+3)%5,$n+5]; | ||
| 57 | } | ||
| 58 | for my $n (10..14){ #scale & push | ||
| 59 | my @node = @{$nodes[$n]}; | ||
| 60 | $node[0] *= 1.2; | ||
| 61 | $node[1] *= 1.2; | ||
| 62 | push @nodes, \@node; | ||
| 63 | push @edges, [$n,$n+5]; | ||
| 64 | } | ||
| 65 | for my $n (15..19){ #connect last 5gon | ||
| 66 | push @edges, [$n,15+($n+1)%5]; | ||
| 67 | } | ||
| 68 | my @adjacent; | ||
| 69 | for (@edges){ | ||
| 70 | push @{$adjacent[$_->[0]]}, $_->[1]; | ||
| 71 | push @{$adjacent[$_->[1]]}, $_->[0]; | ||
| 72 | } | ||
| 73 | return (\@nodes, \@adjacent) | ||
| 74 | } | ||
| 75 | 1 |