freego/main.go

107 lines
1.9 KiB
Go
Raw Normal View History

2022-02-21 19:07:28 -05:00
package freego
2022-02-18 18:36:18 -05:00
2022-02-21 14:22:13 -05:00
import (
"errors"
"fmt"
)
2022-02-21 18:50:03 -05:00
//DummyGame Creates a dummygame
func DummyGame() (*Game, error) {
2022-02-21 14:22:13 -05:00
g := &Game{
2022-02-21 19:07:28 -05:00
Board: NewBoard(4),
2022-03-03 13:15:32 -05:00
State: gameSetup,
2022-02-21 14:22:13 -05:00
}
//Setup terrain
terrain := []struct {
x, y, t int
}{
{1, 1, 1},
{2, 2, 1},
}
for _, tt := range terrain {
2022-02-21 19:07:28 -05:00
res, err := g.Board.AddTerrain(tt.x, tt.y, tt.t)
2022-02-21 14:22:13 -05:00
if err != nil {
return nil, err
}
if !res {
return nil, errors.New("Error creating terrain")
}
}
pieces := []struct {
x, y int
p *Piece
}{
{0, 0, NewPiece(Flag, Blue)},
{3, 0, NewPiece(Spy, Blue)},
{2, 0, NewPiece(Captain, Blue)},
{3, 1, NewPiece(Marshal, Blue)},
{0, 1, NewPiece(Bomb, Blue)},
{1, 2, NewPiece(Flag, Red)},
{3, 2, NewPiece(Spy, Red)},
{2, 3, NewPiece(Captain, Red)},
{0, 2, NewPiece(Marshal, Red)},
{0, 3, NewPiece(Bomb, Red)},
}
for _, tt := range pieces {
res, err := g.SetupPiece(tt.x, tt.y, tt.p)
if err != nil {
return nil, fmt.Errorf("Piece %v,%v:%v", tt.x, tt.y, err)
}
if !res {
return nil, errors.New("error placing dummy piece")
}
}
_, err := g.SetupPiece(0, 0, NewPiece(Flag, Blue))
if err != nil {
return nil, err
}
return g, nil
}
2022-02-21 18:51:42 -05:00
//func main() {
// //red := NewDummyPlayer(Red)
//blue := NewDummyPlayer(Blue)
// _, err := DummyGame()
// if err != nil {
// panic(err)
// }
// return
//}
2022-02-18 18:36:18 -05:00
func addpiece(game *Game, rank int, c Colour, x int, y int) {
2022-02-20 18:36:52 -05:00
res, err := game.SetupPiece(x, y, NewPieceFromInt(rank, c))
2022-02-18 18:36:18 -05:00
if err != nil {
panic(err)
}
if !res {
panic("can't setup")
}
}
func addriver(game *Game, x int, y int) {
2022-02-21 19:07:28 -05:00
res, err := game.Board.AddTerrain(x, y, 1)
2022-02-18 18:36:18 -05:00
if err != nil {
panic(err)
}
if !res {
panic("can't river")
}
}
2022-02-20 18:36:52 -05:00
func printboardcolours(g *Game) {
2022-02-21 19:07:28 -05:00
for i := range g.Board.board {
for j := range g.Board.board[i] {
2022-02-20 18:36:52 -05:00
c := "X"
2022-02-21 19:07:28 -05:00
if g.Board.board[i][j].colour == Red {
2022-02-20 18:36:52 -05:00
c = "R"
2022-02-21 19:07:28 -05:00
} else if g.Board.board[i][j].colour == Blue {
2022-02-20 18:36:52 -05:00
c = "B"
}
fmt.Printf("%v", c)
}
fmt.Println("")
}
}