162 lines
2.6 KiB
Go
162 lines
2.6 KiB
Go
package main
|
|
|
|
type Board struct {
|
|
Sentinal [4]Card
|
|
SenBuf [4]bool
|
|
Scourge [4]Card
|
|
ScoBuf [4]bool
|
|
}
|
|
|
|
func NewBoard() *Board {
|
|
return &Board{
|
|
Sentinal: [4]Card{-1, -1, -1, -1},
|
|
SenBuf: [4]bool{true, true, true, true},
|
|
Scourge: [4]Card{-1, -1, -1, -1},
|
|
ScoBuf: [4]bool{true, true, true, true},
|
|
}
|
|
}
|
|
|
|
func (b *Board) GetRow(id int) []Card {
|
|
if id == 1 {
|
|
return b.Sentinal[:]
|
|
} else {
|
|
return b.Scourge[:]
|
|
}
|
|
}
|
|
|
|
func (b *Board) Move(id, src, dest int) bool {
|
|
var brd [4]Card
|
|
if id == 1 {
|
|
brd = b.Sentinal
|
|
} else {
|
|
brd = b.Scourge
|
|
}
|
|
if brd[src] == -1 {
|
|
return false
|
|
}
|
|
if brd[dest] != -1 {
|
|
return false
|
|
}
|
|
brd[dest] = brd[src]
|
|
brd[src] = -1
|
|
if id == 1 {
|
|
b.Sentinal = brd
|
|
b.SenBuf[dest] = false
|
|
} else {
|
|
b.Scourge = brd
|
|
b.ScoBuf[dest] = false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (b *Board) Play(id int, c Card, dest int) bool {
|
|
var brd [4]Card
|
|
if id == 1 {
|
|
brd = b.Sentinal
|
|
} else {
|
|
brd = b.Scourge
|
|
}
|
|
if brd[dest] != -1 {
|
|
return false
|
|
}
|
|
brd[dest] = c
|
|
if id == 1 {
|
|
b.Sentinal = brd
|
|
b.SenBuf[dest] = false
|
|
} else {
|
|
b.Scourge = brd
|
|
b.ScoBuf[dest] = false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (b *Board) Attack(id int, atk, def int) int {
|
|
var aBrd [4]Card
|
|
var dBrd [4]Card
|
|
var aBuf [4]bool
|
|
var dBuf [4]bool
|
|
if id == 1 {
|
|
aBrd = b.Sentinal
|
|
aBuf = b.SenBuf
|
|
dBrd = b.Scourge
|
|
dBuf = b.ScoBuf
|
|
} else {
|
|
aBrd = b.Scourge
|
|
aBuf = b.ScoBuf
|
|
dBrd = b.Sentinal
|
|
dBuf = b.SenBuf
|
|
}
|
|
if aBrd[atk] == -1 || !aBuf[atk] || !aBrd[atk].CanAttack(atk, def) {
|
|
return -1
|
|
}
|
|
aBuf[atk] = false
|
|
if dBrd[def] == -1 {
|
|
//health damage
|
|
if id == 1 {
|
|
b.Sentinal = aBrd
|
|
b.SenBuf = aBuf
|
|
b.Scourge = dBrd
|
|
b.ScoBuf = dBuf
|
|
} else {
|
|
b.Scourge = aBrd
|
|
b.ScoBuf = aBuf
|
|
b.Sentinal = dBrd
|
|
b.SenBuf = dBuf
|
|
}
|
|
return 1
|
|
}
|
|
//Do actual battle math
|
|
attacker := aBrd[atk]
|
|
defender := dBrd[def]
|
|
//check atk buffs
|
|
for i, v := range aBrd {
|
|
if v == Two {
|
|
attacker = attacker + 1
|
|
}
|
|
if v == Three && (i == atk-1 || i == atk+1) {
|
|
attacker = attacker + 1
|
|
}
|
|
}
|
|
for i, v := range dBrd {
|
|
if v == Two {
|
|
defender = defender + 1
|
|
}
|
|
if v == Three && (i == def-1 || i == def+1) {
|
|
defender = defender + 1
|
|
}
|
|
}
|
|
if attacker > defender {
|
|
dBrd[def] = -1
|
|
if id == 1 {
|
|
b.Sentinal = aBrd
|
|
b.SenBuf = aBuf
|
|
b.Scourge = dBrd
|
|
b.ScoBuf = dBuf
|
|
} else {
|
|
b.Scourge = aBrd
|
|
b.ScoBuf = aBuf
|
|
b.Sentinal = dBrd
|
|
b.SenBuf = dBuf
|
|
}
|
|
return 0
|
|
}
|
|
if attacker == defender {
|
|
aBrd[atk] = -1
|
|
dBrd[def] = -1
|
|
if id == 1 {
|
|
b.Sentinal = aBrd
|
|
b.SenBuf = aBuf
|
|
b.Scourge = dBrd
|
|
b.ScoBuf = dBuf
|
|
} else {
|
|
b.Scourge = aBrd
|
|
b.ScoBuf = aBuf
|
|
b.Sentinal = dBrd
|
|
b.SenBuf = dBuf
|
|
}
|
|
return 0
|
|
}
|
|
return -1
|
|
|
|
}
|