actually use GetRow since I can, implement 2 and 3, cards have owners and positions
This commit is contained in:
parent
22a3e0c8e8
commit
d1845760fe
@ -2,8 +2,6 @@ package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Board struct {
|
||||
@ -13,8 +11,8 @@ type Board struct {
|
||||
|
||||
func NewBoard() *Board {
|
||||
return &Board{
|
||||
Sentinal: [4]*Card{NewCard(-1, uuid.Nil), NewCard(-1, uuid.Nil), NewCard(-1, uuid.Nil), NewCard(-1, uuid.Nil)},
|
||||
Scourge: [4]*Card{NewCard(-1, uuid.Nil), NewCard(-1, uuid.Nil), NewCard(-1, uuid.Nil), NewCard(-1, uuid.Nil)},
|
||||
Sentinal: [4]*Card{NewEmpty(0), NewEmpty(1), NewEmpty(2), NewEmpty(3)},
|
||||
Scourge: [4]*Card{NewEmpty(0), NewEmpty(1), NewEmpty(2), NewEmpty(3)},
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +21,7 @@ func (b *Board) String() string {
|
||||
}
|
||||
|
||||
func (b *Board) GetRow(id int) []*Card {
|
||||
if id == 1 {
|
||||
if id == SentinalID {
|
||||
return b.Sentinal[:]
|
||||
} else {
|
||||
return b.Scourge[:]
|
||||
@ -31,51 +29,36 @@ func (b *Board) GetRow(id int) []*Card {
|
||||
}
|
||||
|
||||
func (b *Board) GetCard(id int, pos int) *Card {
|
||||
if id == SentinalID {
|
||||
return b.Sentinal[pos]
|
||||
} else {
|
||||
return b.Scourge[pos]
|
||||
}
|
||||
return b.GetRow(id)[pos]
|
||||
}
|
||||
|
||||
func (b *Board) Remove(c *Card) {
|
||||
for k, v := range b.Sentinal {
|
||||
if v.Id == c.Id {
|
||||
b.Sentinal[k] = NewCard(-1, uuid.Nil)
|
||||
b.Sentinal[k] = NewEmpty(k)
|
||||
}
|
||||
}
|
||||
for k, v := range b.Scourge {
|
||||
if v.Id == c.Id {
|
||||
b.Scourge[k] = NewCard(-1, uuid.Nil)
|
||||
b.Scourge[k] = NewEmpty(k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Board) Empty(id int) bool {
|
||||
res := true
|
||||
if id == SentinalID {
|
||||
for _, v := range b.Sentinal {
|
||||
row := b.GetRow(id)
|
||||
for _, v := range row {
|
||||
if !v.Empty() {
|
||||
res = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, v := range b.Scourge {
|
||||
if !v.Empty() {
|
||||
res = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func (b *Board) CanMove(id, src, dest int) bool {
|
||||
var brd [4]*Card
|
||||
if id == SentinalID {
|
||||
brd = b.Sentinal
|
||||
} else {
|
||||
brd = b.Scourge
|
||||
}
|
||||
brd := b.GetRow(id)
|
||||
if brd[src].Empty() {
|
||||
return false
|
||||
}
|
||||
@ -105,7 +88,7 @@ func (b *Board) Move(id, src, dest int) bool {
|
||||
return false
|
||||
}
|
||||
brd[dest] = brd[src]
|
||||
brd[src] = NewCard(-1, uuid.Nil)
|
||||
brd[src] = NewEmpty(src)
|
||||
if id == SentinalID {
|
||||
b.Sentinal = brd
|
||||
} else {
|
||||
@ -115,12 +98,7 @@ func (b *Board) Move(id, src, dest int) bool {
|
||||
}
|
||||
|
||||
func (b *Board) CanPlay(id int, c *Card, dest int) bool {
|
||||
var brd [4]*Card
|
||||
if id == SentinalID {
|
||||
brd = b.Sentinal
|
||||
} else {
|
||||
brd = b.Scourge
|
||||
}
|
||||
brd := b.GetRow(id)
|
||||
if !brd[dest].Empty() {
|
||||
return false
|
||||
}
|
||||
@ -128,33 +106,18 @@ func (b *Board) CanPlay(id int, c *Card, dest int) bool {
|
||||
}
|
||||
|
||||
func (b *Board) Play(id int, c *Card, dest int, should bool) bool {
|
||||
var brd [4]*Card
|
||||
if id == SentinalID {
|
||||
brd = b.Sentinal
|
||||
} else {
|
||||
brd = b.Scourge
|
||||
}
|
||||
if !brd[dest].Empty() {
|
||||
return false
|
||||
}
|
||||
brd := b.GetRow(id)
|
||||
if should {
|
||||
brd[dest] = c
|
||||
}
|
||||
if id == SentinalID {
|
||||
b.Sentinal = brd
|
||||
c.Position = dest
|
||||
} else {
|
||||
b.Scourge = brd
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *Board) CanAttack(id, atk, def int) bool {
|
||||
var aBrd [4]*Card
|
||||
if id == SentinalID {
|
||||
aBrd = b.Sentinal
|
||||
} else {
|
||||
aBrd = b.Scourge
|
||||
}
|
||||
aBrd := b.GetRow(id)
|
||||
if aBrd[atk].Empty() || aBrd[atk].Sick || atk != def {
|
||||
return false
|
||||
}
|
||||
@ -186,7 +149,7 @@ func (b *Board) Attack(id int, atk, def int) int {
|
||||
attacker := aBrd[atk].Power
|
||||
defender := dBrd[def].Power
|
||||
if attacker > defender {
|
||||
dBrd[def] = NewCard(-1, uuid.Nil)
|
||||
dBrd[def] = NewEmpty(def)
|
||||
if id == SentinalID {
|
||||
b.Sentinal = aBrd
|
||||
b.Scourge = dBrd
|
||||
@ -197,8 +160,8 @@ func (b *Board) Attack(id int, atk, def int) int {
|
||||
return 0
|
||||
}
|
||||
if attacker == defender {
|
||||
aBrd[atk] = NewCard(-1, uuid.Nil)
|
||||
dBrd[def] = NewCard(-1, uuid.Nil)
|
||||
aBrd[atk] = NewEmpty(atk)
|
||||
dBrd[def] = NewEmpty(def)
|
||||
if id == 1 {
|
||||
b.Sentinal = aBrd
|
||||
b.Scourge = dBrd
|
||||
|
@ -8,10 +8,13 @@ import (
|
||||
|
||||
type Card struct {
|
||||
Type CardType `json:"type"`
|
||||
BasePower int `json:"base_power"`
|
||||
Power int `json:"power"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
Sick bool `json:"sick"`
|
||||
Counters int `json:"counters"`
|
||||
Owner int `json:"owner"`
|
||||
Position int `json:"position"`
|
||||
}
|
||||
|
||||
type CardType int
|
||||
@ -38,16 +41,32 @@ func (c CardType) String() string {
|
||||
return []string{"V", "A", "2", "3", "4", "5", "6", "7", "8"}[c]
|
||||
}
|
||||
|
||||
func NewCard(v int, id uuid.UUID) *Card {
|
||||
func NewCard(v, o, p int, id uuid.UUID) *Card {
|
||||
if id == uuid.Nil {
|
||||
id = uuid.New()
|
||||
}
|
||||
return &Card{
|
||||
Type: CardType(v),
|
||||
BasePower: OraclePower(CardType(v), nil),
|
||||
Power: OraclePower(CardType(v), nil),
|
||||
Id: id,
|
||||
Sick: false,
|
||||
Counters: 0,
|
||||
Owner: o,
|
||||
Position: p,
|
||||
}
|
||||
}
|
||||
|
||||
func NewEmpty(p int) *Card {
|
||||
return &Card{
|
||||
Type: EmptyValue,
|
||||
BasePower: -1,
|
||||
Power: -1,
|
||||
Id: uuid.New(),
|
||||
Sick: false,
|
||||
Counters: 0,
|
||||
Owner: -1,
|
||||
Position: p,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,11 @@ type Deck struct {
|
||||
Cards []*Card `json:"cards"`
|
||||
}
|
||||
|
||||
func NewDeck() *Deck {
|
||||
cards := []*Card{NewCard(0, uuid.Nil)}
|
||||
func NewDeck(owner int) *Deck {
|
||||
cards := []*Card{NewCard(0, owner, -1, uuid.Nil)}
|
||||
for i := 0; i < 3; i++ {
|
||||
for j := 1; j < 9; j++ {
|
||||
cards = append(cards, NewCard(j, uuid.Nil))
|
||||
cards = append(cards, NewCard(j, owner, -1, uuid.Nil))
|
||||
}
|
||||
}
|
||||
return &Deck{
|
||||
|
@ -42,8 +42,8 @@ type Game struct {
|
||||
}
|
||||
|
||||
func NewGame() *Game {
|
||||
deckA := NewDeck()
|
||||
deckB := NewDeck()
|
||||
deckA := NewDeck(SentinalID)
|
||||
deckB := NewDeck(ScourgeID)
|
||||
deckA.Shuffle()
|
||||
deckB.Shuffle()
|
||||
return &Game{
|
||||
@ -258,7 +258,7 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
||||
x_i, _ := strconv.Atoi(cmd_s[1])
|
||||
y_i, _ := strconv.Atoi(cmd_s[2])
|
||||
if g.GameBoard.CanMove(g.CurrentTurn, x_i, y_i) {
|
||||
OracleMove(g.GameBoard.GetCard(g.CurrentTurn, x_i), g)
|
||||
OracleMove(g.GameBoard.GetCard(g.CurrentTurn, x_i), x_i, y_i, g)
|
||||
g.GameBoard.Move(g.CurrentTurn, x_i, y_i)
|
||||
return DeckFromCards(g.GameBoard.GetRow(g.CurrentTurn))
|
||||
} else {
|
||||
@ -302,8 +302,10 @@ func (g *Game) PlayerAct(id int, cmd string) *Deck {
|
||||
shouldPlace := true
|
||||
if g.GameBoard.CanPlay(g.CurrentTurn, card, y_i) {
|
||||
shouldPlace = OracleCast(curr.Hand[x_i], g)
|
||||
_ = g.GameBoard.Play(g.CurrentTurn, card, y_i, shouldPlace)
|
||||
placed := g.GameBoard.Play(g.CurrentTurn, card, y_i, shouldPlace)
|
||||
if placed {
|
||||
OracleEnters(curr.Hand[x_i], g)
|
||||
}
|
||||
curr.Hand = append(curr.Hand[:x_i], curr.Hand[x_i+1:]...)
|
||||
return DeckFromCards(g.GameBoard.GetRow(g.CurrentTurn))
|
||||
} else {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package game
|
||||
|
||||
import "log"
|
||||
|
||||
func OracleUpkeep(c *Card, g *Game) {
|
||||
switch c.Type {
|
||||
case Eight:
|
||||
@ -28,22 +30,77 @@ func OracleEnters(c *Card, g *Game) {
|
||||
switch c.Type {
|
||||
case Two:
|
||||
//+1 to all
|
||||
if g.CurrentTurn == SentinalID {
|
||||
if c.Owner == SentinalID {
|
||||
for _, v := range g.GameBoard.Sentinal {
|
||||
v.Power = v.Power + 1
|
||||
}
|
||||
} else {
|
||||
} else if c.Owner == ScourgeID {
|
||||
for _, v := range g.GameBoard.Scourge {
|
||||
v.Power = v.Power + 1
|
||||
}
|
||||
} else {
|
||||
log.Println("Trying to lookup an ETB when card not on field")
|
||||
}
|
||||
case Three:
|
||||
//+1 around it
|
||||
if c.Owner == SentinalID {
|
||||
if c.Position-1 >= 0 {
|
||||
g.GameBoard.Sentinal[c.Position-1].Power = g.GameBoard.Sentinal[c.Position-1].Power + 1
|
||||
}
|
||||
if c.Position+1 <= 3 {
|
||||
g.GameBoard.Sentinal[c.Position+1].Power = g.GameBoard.Sentinal[c.Position+1].Power + 1
|
||||
}
|
||||
|
||||
}
|
||||
if c.Owner == ScourgeID {
|
||||
if c.Position-1 >= 0 {
|
||||
g.GameBoard.Scourge[c.Position-1].Power = g.GameBoard.Scourge[c.Position-1].Power + 1
|
||||
}
|
||||
if c.Position+1 <= 3 {
|
||||
g.GameBoard.Scourge[c.Position+1].Power = g.GameBoard.Scourge[c.Position+1].Power + 1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func OracleLeaves(c *Card, g *Game) {
|
||||
switch c.Type {
|
||||
case Two:
|
||||
//remove +1 to all
|
||||
if c.Owner == SentinalID {
|
||||
for _, v := range g.GameBoard.Sentinal {
|
||||
v.Power = v.Power - 1
|
||||
}
|
||||
} else if c.Owner == ScourgeID {
|
||||
for _, v := range g.GameBoard.Scourge {
|
||||
v.Power = v.Power - 1
|
||||
}
|
||||
} else {
|
||||
log.Println("Trying to lookup an LTB when card not on field")
|
||||
}
|
||||
case Three:
|
||||
//+1 around it
|
||||
if c.Owner == SentinalID {
|
||||
if c.Position-1 >= 0 {
|
||||
g.GameBoard.Sentinal[c.Position-1].Power = g.GameBoard.Sentinal[c.Position-1].Power - 1
|
||||
}
|
||||
if c.Position+1 <= 3 {
|
||||
g.GameBoard.Sentinal[c.Position+1].Power = g.GameBoard.Sentinal[c.Position+1].Power - 1
|
||||
}
|
||||
|
||||
}
|
||||
if c.Owner == ScourgeID {
|
||||
if c.Position-1 >= 0 {
|
||||
g.GameBoard.Scourge[c.Position-1].Power = g.GameBoard.Scourge[c.Position-1].Power - 1
|
||||
}
|
||||
if c.Position+1 <= 3 {
|
||||
g.GameBoard.Scourge[c.Position+1].Power = g.GameBoard.Scourge[c.Position+1].Power - 1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -59,8 +116,16 @@ func OraclePower(c CardType, g *Game) int {
|
||||
return int(c)
|
||||
}
|
||||
|
||||
func OracleMove(c *Card, g *Game) {
|
||||
func OracleMove(c *Card, src, dest int, g *Game) {
|
||||
c.Sick = true
|
||||
switch c.Type {
|
||||
case Three:
|
||||
row := g.GameBoard.GetRow(c.Owner)
|
||||
row[src-1].Power = row[src-1].Power - 1
|
||||
row[src+1].Power = row[src+1].Power - 1
|
||||
row[dest-1].Power = row[dest-1].Power + 1
|
||||
row[dest+1].Power = row[dest+1].Power + 1
|
||||
}
|
||||
}
|
||||
|
||||
func OracleAttack(c *Card, g *Game) {
|
||||
|
Loading…
Reference in New Issue
Block a user