ExamplesΒΆ

from hexea import Yboard, Hexboard

yb = Yboard(5)
print(yb)
.
   .
.     .
   .     .
.     .     .
   .     .
.     .
   .
.
# method chaining
print (
    yb
    .move(2, 1)
    .move(1, 1)
)
.
   .
.     .
   O     .
.     X     .
   .     .
.     .
   .
.
# move modifies in-place
print(yb)
.
   .
.     .
   O     .
.     X     .
   .     .
.     .
   .
.
from copy import copy

yb2 = copy(yb)
print(yb.random_playout())
O
   O
O     X
   O     X
X     X     X
   X     O
O     X
   X
O
print(yb2)
.
   .
.     .
   O     .
.     X     .
   .     .
.     .
   .
.
hb = Hexboard(5)

print(hb)
 xxxxxxxxxxxxxxxxxxx
o .   .   .   .   . o
 o                   o
  o .   .   .   .   . o
   o                   o
    o .   .   .   .   . o
     o                   o
      o .   .   .   .   . o
       o                   o
        o .   .   .   .   . o
         xxxxxxxxxxxxxxxxxxx
print(hb.random_playout(quick=False))
 xxxxxxxxxxxxxxxxxxx
o X   .   O   .   O o
 o                   o
  o X   X   X   O   X o
   o                   o
    o X   O   .   X   O o
     o                   o
      o X   O   O   O   X o
       o                   o
        o O   .   X   O   . o
         xxxxxxxxxxxxxxxxxxx
print(hb.get_winner())
O
hb2 = Hexboard(3)
l = hb2.get_list_of_dicts(5)
print(l)
[{'cell0_0': <Marker.red: 1>, 'cell1_0': <Marker.red: 1>, 'cell0_1': <Marker.red: 1>, 'cell2_0': <Marker.blue: -1>, 'cell1_1': <Marker.red: 1>, 'cell0_2': <Marker.blue: -1>, 'cell2_1': <Marker.blue: -1>, 'cell1_2': <Marker.blue: -1>, 'cell2_2': <Marker.red: 1>, 'winner': <Marker.blue: -1>}, {'cell0_0': <Marker.red: 1>, 'cell1_0': <Marker.red: 1>, 'cell0_1': <Marker.blue: -1>, 'cell2_0': <Marker.blue: -1>, 'cell1_1': <Marker.blue: -1>, 'cell0_2': <Marker.red: 1>, 'cell2_1': <Marker.red: 1>, 'cell1_2': <Marker.red: 1>, 'cell2_2': <Marker.blue: -1>, 'winner': <Marker.blue: -1>}, {'cell0_0': <Marker.red: 1>, 'cell1_0': <Marker.blue: -1>, 'cell0_1': <Marker.blue: -1>, 'cell2_0': <Marker.red: 1>, 'cell1_1': <Marker.red: 1>, 'cell0_2': <Marker.blue: -1>, 'cell2_1': <Marker.red: 1>, 'cell1_2': <Marker.blue: -1>, 'cell2_2': <Marker.red: 1>, 'winner': <Marker.red: 1>}, {'cell0_0': <Marker.blue: -1>, 'cell1_0': <Marker.red: 1>, 'cell0_1': <Marker.red: 1>, 'cell2_0': <Marker.red: 1>, 'cell1_1': <Marker.blue: -1>, 'cell0_2': <Marker.red: 1>, 'cell2_1': <Marker.blue: -1>, 'cell1_2': <Marker.red: 1>, 'cell2_2': <Marker.blue: -1>, 'winner': <Marker.red: 1>}, {'cell0_0': <Marker.blue: -1>, 'cell1_0': <Marker.blue: -1>, 'cell0_1': <Marker.blue: -1>, 'cell2_0': <Marker.red: 1>, 'cell1_1': <Marker.red: 1>, 'cell0_2': <Marker.red: 1>, 'cell2_1': <Marker.red: 1>, 'cell1_2': <Marker.red: 1>, 'cell2_2': <Marker.blue: -1>, 'winner': <Marker.red: 1>}]
import pandas as pd
df = pd.DataFrame.from_records(l)
df
cell0_0 cell1_0 cell0_1 cell2_0 cell1_1 cell0_2 cell2_1 cell1_2 cell2_2 winner
0 X X X O X O O O X O
1 X X O O O X X X O O
2 X O O X X O X O X X
3 O X X X O X O X O X
4 O O O X X X X X O X
# For ML training we probably want integer values instead of Marker
df.astype(int)
cell0_0 cell1_0 cell0_1 cell2_0 cell1_1 cell0_2 cell2_1 cell1_2 cell2_2 winner
0 1 1 1 -1 1 -1 -1 -1 1 -1
1 1 1 -1 -1 -1 1 1 1 -1 -1
2 1 -1 -1 1 1 -1 1 -1 1 1
3 -1 1 1 1 -1 1 -1 1 -1 1
4 -1 -1 -1 1 1 1 1 1 -1 1