just use full debug info for now

This commit is contained in:
stryan 2021-07-16 14:53:45 -04:00
parent 8062c99ee6
commit c111e09ab5
5 changed files with 155 additions and 35 deletions

View File

@ -1,5 +1,7 @@
package main
import "fmt"
type Board struct {
Sentinal [4]Card
Scourge [4]Card
@ -7,11 +9,15 @@ type Board struct {
func NewBoard() *Board {
return &Board{
Sentinal: [4]Card{nil, nil, nil, nil},
Scourge: [4]Card{nil, nil, nil, nil},
Sentinal: [4]Card{NewCard(-1), NewCard(-1), NewCard(-1), NewCard(-1)},
Scourge: [4]Card{NewCard(-1), NewCard(-1), NewCard(-1), NewCard(-1)},
}
}
func (b *Board) String() string {
return fmt.Sprintf("---------\n|%v|%v|%v|%v|\n---------\n|%v|%v|%v|%v|\n---------\n", b.Sentinal[0], b.Sentinal[1], b.Sentinal[2], b.Sentinal[3], b.Scourge[0], b.Scourge[1], b.Scourge[2], b.Scourge[3])
}
func (b *Board) GetRow(id int) []Card {
if id == 1 {
return b.Sentinal[:]
@ -27,14 +33,14 @@ func (b *Board) Move(id, src, dest int) bool {
} else {
brd = b.Scourge
}
if brd[src] == nil {
if brd[src].Empty() {
return false
}
if brd[dest] != nil {
if !brd[dest].Empty() {
return false
}
brd[dest] = brd[src]
brd[src] = nil
brd[src] = NewCard(-1)
if id == 1 {
b.Sentinal = brd
} else {
@ -50,7 +56,7 @@ func (b *Board) CanPlay(id int, c *Card, dest int) bool {
} else {
brd = b.Scourge
}
if brd[dest] != nil {
if !brd[dest].Empty() {
return false
}
return true
@ -63,7 +69,7 @@ func (b *Board) Play(id int, c *Card, dest int) bool {
} else {
brd = b.Scourge
}
if brd[dest] != nil {
if !brd[dest].Empty() {
return false
}
brd[dest] = *c
@ -85,11 +91,11 @@ func (b *Board) Attack(id int, atk, def int) int {
aBrd = b.Scourge
dBrd = b.Sentinal
}
if aBrd[atk] == nil || !aBrd[atk].CanAttack(atk, def) {
if aBrd[atk].Empty() || !aBrd[atk].CanAttack(atk, def) {
return -1
}
aBrd[atk].Acted()
if dBrd[def] == nil {
if dBrd[def].Empty() {
//health damage
if id == 1 {
b.Sentinal = aBrd
@ -122,7 +128,7 @@ func (b *Board) Attack(id int, atk, def int) int {
}
}
if attacker > defender {
dBrd[def] = nil
dBrd[def] = NewCard(-1)
if id == 1 {
b.Sentinal = aBrd
b.Scourge = dBrd
@ -133,8 +139,8 @@ func (b *Board) Attack(id int, atk, def int) int {
return 0
}
if attacker == defender {
aBrd[atk] = nil
dBrd[def] = nil
aBrd[atk] = NewCard(-1)
dBrd[def] = NewCard(-1)
if id == 1 {
b.Sentinal = aBrd
b.Scourge = dBrd

37
card.go
View File

@ -1,5 +1,7 @@
package main
import "fmt"
type Card interface {
Cast(g *Game) *Game
Upkeep(g *Game) *Game
@ -7,6 +9,8 @@ type Card interface {
Enters(g *Game) *Game
Value() CardValue
Acted()
Empty() bool
String() string
CanAttack(int, int) bool
}
@ -38,6 +42,14 @@ func (g *GenericCard) Acted() {
g.Sick = true
}
func (g *GenericCard) Empty() bool {
return false
}
func (g *GenericCard) String() string {
return fmt.Sprintf("%v", g.Val)
}
func (g *GenericCard) CanAttack(x, y int) bool {
if x == y && !g.Sick {
return true
@ -58,13 +70,26 @@ const (
Seven
Eight
)
const (
EmptyValue CardValue = -1
)
func (c CardValue) String() string {
if c == -1 {
return " "
}
return []string{"V", "A", "2", "3", "4", "5", "6", "7", "8"}[c]
}
func NewCard(v int) Card {
switch v {
case -1:
return &EmptyCard{
&GenericCard{
Val: EmptyValue,
Sick: false,
},
}
case 1:
return &AceCard{
&GenericCard{
@ -102,6 +127,14 @@ func NewCard(v int) Card {
}
}
type EmptyCard struct {
*GenericCard
}
func (e *EmptyCard) Empty() bool {
return true
}
type AceCard struct {
*GenericCard
}
@ -148,8 +181,8 @@ type Valkyrie struct {
}
func (v *Valkyrie) Cast(g *Game) *Game {
g.GameBoard.Sentinal = [4]Card{nil, nil, nil, nil}
g.GameBoard.Scourge = [4]Card{nil, nil, nil, nil}
g.GameBoard.Sentinal = [4]Card{NewCard(-1), NewCard(-1), NewCard(-1), NewCard(-1)}
g.GameBoard.Scourge = [4]Card{NewCard(-1), NewCard(-1), NewCard(-1), NewCard(-1)}
return g
}

10
deck.go
View File

@ -1,6 +1,9 @@
package main
import "math/rand"
import (
"math/rand"
"time"
)
type Deck struct {
Cards []Card
@ -9,7 +12,7 @@ type Deck struct {
func NewDeck() *Deck {
cards := []Card{NewCard(0)}
for i := 0; i < 3; i++ {
for j := 1; j < 10; j++ {
for j := 1; j < 9; j++ {
cards = append(cards, Card(NewCard(j)))
}
}
@ -20,8 +23,9 @@ func NewDeck() *Deck {
func (d *Deck) Shuffle() {
cards := d.Cards
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := range cards {
j := rand.Intn(i + 1)
j := r.Intn(i + 1)
cards[i], cards[j] = cards[j], cards[i]
}
d.Cards = cards

100
game.go
View File

@ -1,19 +1,34 @@
package main
import (
"fmt"
"strconv"
"strings"
)
type GameStatus int
const (
StatusLobby = iota
StatusReady
StatusPlaying
StatusStop
)
func (g GameStatus) String() string {
return []string{"Lobby", "Ready", "Playing", "Stopped"}[g]
}
type Game struct {
GameBoard *Board
SentinalPlayer *Player
ScourgePlayer *Player
sentinalDeck *Deck
scourgeDeck *Deck
SentinalDeck *Deck
ScourgeDeck *Deck
CurrentTurn int
cardBuffer []Card
CardBuffer []Card
CanDraw bool
Status GameStatus
}
func NewGame() *Game {
@ -25,21 +40,67 @@ func NewGame() *Game {
GameBoard: NewBoard(),
SentinalPlayer: NewPlayer("Sentinal", 1),
ScourgePlayer: NewPlayer("Scourge", 2),
sentinalDeck: deckA,
scourgeDeck: deckB,
SentinalDeck: deckA,
ScourgeDeck: deckB,
CurrentTurn: 0, //start with no turn
cardBuffer: []Card{},
CardBuffer: []Card{},
CanDraw: false,
Status: StatusLobby,
}
}
func (g *Game) String() string {
return fmt.Sprintf("Sen(%v): %v\n\n%v\n\nSco(%v): %v\n%v %v\n%v\n", g.SentinalPlayer.Life, g.SentinalPlayer.Hand, g.GameBoard, g.ScourgePlayer.Life, g.ScourgePlayer.Hand, g.Status, g.CanDraw, g.CardBuffer)
}
func (g *Game) PlayerStateAct(id int, cmd string) *Game {
switch cmd {
case "i":
//info
case "d":
//debug game state
return g
case "g":
//game state
if id == 1 {
return &Game{
GameBoard: g.GameBoard,
SentinalPlayer: g.SentinalPlayer,
ScourgePlayer: nil,
SentinalDeck: g.SentinalDeck,
ScourgeDeck: nil,
CurrentTurn: g.CurrentTurn,
CardBuffer: nil,
CanDraw: g.CanDraw,
Status: g.Status,
}
} else {
return &Game{
GameBoard: g.GameBoard,
SentinalPlayer: nil,
ScourgePlayer: g.ScourgePlayer,
SentinalDeck: nil,
ScourgeDeck: g.ScourgeDeck,
CurrentTurn: g.CurrentTurn,
CardBuffer: nil,
CanDraw: g.CanDraw,
Status: g.Status,
}
}
case "b":
//begin game
g.Status = StatusReady
//TODO check for ready on both accounts first
g.SentinalPlayer.Hand = g.SentinalDeck.Cards[len(g.SentinalDeck.Cards)-5 : len(g.SentinalDeck.Cards)]
g.SentinalDeck.Cards = g.SentinalDeck.Cards[0 : len(g.SentinalDeck.Cards)-5]
g.ScourgePlayer.Hand = g.ScourgeDeck.Cards[len(g.ScourgeDeck.Cards)-5 : len(g.ScourgeDeck.Cards)]
g.SentinalDeck.Cards = g.ScourgeDeck.Cards[0 : len(g.ScourgeDeck.Cards)-5]
case "s":
//start turn
if g.Status == StatusReady {
g.Status = StatusPlaying
g.CurrentTurn = id
g.CanDraw = false
}
if id != g.CurrentTurn {
return nil
}
@ -59,7 +120,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) *Game {
if id != g.CurrentTurn {
return nil
}
g.cardBuffer = []Card{}
g.CardBuffer = []Card{}
if id == 1 {
for _, v := range g.GameBoard.Sentinal {
v.Endstep(g)
@ -89,11 +150,11 @@ func (g *Game) PlayerAct(id int, cmd string) []Card {
if id == g.SentinalPlayer.Id {
curr = g.SentinalPlayer
opp = g.ScourgePlayer
currD = g.sentinalDeck
currD = g.SentinalDeck
} else {
curr = g.ScourgePlayer
opp = g.SentinalPlayer
currD = g.scourgeDeck
currD = g.ScourgeDeck
}
cmd_s := strings.Split(cmd, " ")
if len(cmd_s) < 1 {
@ -105,10 +166,13 @@ func (g *Game) PlayerAct(id int, cmd string) []Card {
if !g.CanDraw {
return nil
}
g.cardBuffer = currD.Scry(curr.Life)
return g.cardBuffer
g.CardBuffer = currD.Scry(curr.Life)
return g.CardBuffer
case "d":
//draw: return player hand
if !g.CanDraw {
return nil
}
if len(cmd_s) != 2 || !g.CanDraw {
return nil
}
@ -116,15 +180,17 @@ func (g *Game) PlayerAct(id int, cmd string) []Card {
if err != nil {
panic(err)
}
x := g.cardBuffer[x_i]
buf := g.cardBuffer
x := g.CardBuffer[x_i]
buf := g.CardBuffer
for i, v := range buf {
if v == x {
buf = append(buf[:i], buf[i+1:]...)
}
}
currD.Bottom(buf)
return []Card{x}
curr.Hand = append(curr.Hand, x)
g.CanDraw = false
return curr.Hand
case "m":
//move: return player board or [] if invalid
@ -157,7 +223,7 @@ func (g *Game) PlayerAct(id int, cmd string) []Card {
}
case "p":
//play: return player boad or [] if invalid
if len(cmd_s) != 2 {
if len(cmd_s) != 3 {
return nil
}
x_i, _ := strconv.Atoi(cmd_s[1])

13
main.go
View File

@ -5,10 +5,21 @@ import "fmt"
func main() {
g := NewGame()
fmt.Println(g.GameBoard)
g.PlayerStateAct(1, "b")
g.PlayerStateAct(1, "s")
tmp := g.PlayerStateAct(1, "d")
fmt.Println("begin")
fmt.Println(tmp)
fmt.Println("scry")
scry := g.PlayerAct(1, "s")
fmt.Println(scry)
fmt.Println("draw")
g.PlayerAct(1, "d 1")
h2 := g.PlayerStateAct(1, "d")
fmt.Println(h2)
fmt.Println("play")
g.PlayerAct(1, "p 1 3")
b2 := g.PlayerStateAct(1, "d")
fmt.Println(b2)
}