Commit a211fc18 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

changed to use new functions

parent b207087a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -25,8 +25,8 @@ func main() {
	fmt.Fprintf(os.Stderr, "Seed: %d\n", seed)
	rand.Seed(seed)

	g := game.New()
	g.AddPlayer(name1, &cross.Cross{})
	g.AddPlayer(name2, &nought.Nought{})
	g := game.NewGame()
	g.AddPlayer(name1, cross.NewCross())
	g.AddPlayer(name2, nought.NewNought())
	g.Run()
}
+9 −10
Original line number Diff line number Diff line
@@ -15,10 +15,10 @@ type Game struct {
	Players map[int]player.Player
}

// New ...
func New() *Game {
// NewGame ...
func NewGame() *Game {
	return &Game{
		Grid:    grid.New(),
		Grid:    grid.NewGrid(),
		Players: make(map[int]player.Player),
	}
}
@@ -33,17 +33,16 @@ func (g *Game) AddPlayer(name string, cell grid.Cell) error {
// Run ...
func (g *Game) Run() {
	for i := 0; i < 9; i++ {
		pl := i % 2
		pl := i % len(g.Players)
		p := g.Players[pl]
		pos := p.Next(g.Grid)
		g.Grid.Data[pos] = p.Cell()

		c0 := g.Grid.Data[grid.Pos(0, 0)]
		c1 := g.Grid.Data[grid.Pos(1, 0)]
		c2 := g.Grid.Data[grid.Pos(2, 0)]
		if (c0 == c1) && (c1 == c2) && (c0 == c2) {

		}
		//c0 := g.Grid.Data[grid.Pos(0, 0)]
		//c1 := g.Grid.Data[grid.Pos(1, 0)]
		//c2 := g.Grid.Data[grid.Pos(2, 0)]
		//if (c0 == c1) && (c1 == c2) && (c0 == c2) {
		//}

		fmt.Fprintf(os.Stderr, "Round %d: %s\n%s", i+1, p.Name(), g.Grid)

+3 −3
Original line number Diff line number Diff line
@@ -13,10 +13,10 @@ func TestGame(t *testing.T) {
	seed := int64(1557681173)
	rand.Seed(seed)

	c1 := &cross.Cross{}
	c2 := &nought.Nought{}
	c1 := cross.NewCross()
	c2 := nought.NewNought()

	g := New()
	g := NewGame()
	g.AddPlayer("Player 1", c1)
	g.AddPlayer("Player 2", c2)
	g.Run()
+2 −2
Original line number Diff line number Diff line
@@ -11,8 +11,8 @@ type Grid struct {
	Data map[Position]Cell
}

// New ...
func New() *Grid {
// NewGrid ...
func NewGrid() *Grid {
	g := &Grid{
		Data: make(map[Position]Cell),
	}
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import (
)

func TestDisplayGrid(t *testing.T) {
	g := New()
	g := NewGrid()
	s := g.String()
	r := " ┃ ┃ \n━╋━╋━\n ┃ ┃ \n━╋━╋━\n ┃ ┃ \n"
	if strings.Compare(s, r) != 0 {