2022-04-13 07:48:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-04-13 23:09:58 +00:00
|
|
|
"fmt"
|
2022-04-13 07:48:22 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2022-04-13 23:09:58 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2022-04-13 07:48:22 +00:00
|
|
|
|
|
|
|
"git.tuxpa.in/a/card_id/common/game"
|
2022-04-13 23:09:58 +00:00
|
|
|
"git.tuxpa.in/a/card_id/common/game/card"
|
2022-04-13 07:48:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-04-13 23:09:58 +00:00
|
|
|
deal, err := card.NewDealer().ReadFromRoot(os.Getenv("CARD_DATA_DIR"))
|
2022-04-13 07:48:22 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
|
2022-04-13 23:09:58 +00:00
|
|
|
g := game.Game{Dealer: deal, Lives: 3}
|
2022-04-13 07:48:22 +00:00
|
|
|
|
2022-04-13 23:09:58 +00:00
|
|
|
trial := g.CreateTrial(3, 1)
|
|
|
|
for {
|
|
|
|
if trial != nil {
|
|
|
|
if trial.CheckSelection() {
|
|
|
|
fmt.Print("\n match found!!!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Printf("\ncardid > ")
|
|
|
|
var args [4]string
|
|
|
|
alen, _ := fmt.Scanln(&args[0], &args[1], &args[2], &args[3])
|
|
|
|
if alen < 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(args[0], "c") {
|
|
|
|
args[1] = string(strip([]byte(args[0])))
|
|
|
|
args[0] = "c"
|
|
|
|
alen = 2
|
|
|
|
}
|
|
|
|
switch args[0] {
|
|
|
|
case "help":
|
|
|
|
fmt.Printf("show, select, update")
|
|
|
|
case "show":
|
|
|
|
fmt.Printf("current hand:\n %+v", trial.Show())
|
|
|
|
case "select", "sel", "c":
|
|
|
|
if alen > 1 {
|
|
|
|
num, _ := strconv.Atoi(args[1])
|
|
|
|
cd, err := trial.SelectCard(num)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
if cd.Id > 0 {
|
|
|
|
msg := fmt.Sprintf(`
|
|
|
|
card %d was %s | lives: %d
|
|
|
|
current hand:
|
|
|
|
%s`, num, cd.Name, trial.Lives, trial.ShowString())
|
|
|
|
fmt.Printf(msg)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
trial.SelectCard(0)
|
|
|
|
}
|
|
|
|
case "debug":
|
|
|
|
fmt.Println(trial)
|
|
|
|
case "exit", "quit", "q":
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func strip(s []byte) []byte {
|
|
|
|
n := 0
|
|
|
|
for _, b := range s {
|
|
|
|
if ('0' <= b && b <= '9') ||
|
|
|
|
b == ' ' {
|
|
|
|
s[n] = b
|
|
|
|
n++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s[:n]
|
2022-04-13 07:48:22 +00:00
|
|
|
}
|