|
|
|
@ -91,6 +91,8 @@ func (g *Game) Reset() {
@@ -91,6 +91,8 @@ func (g *Game) Reset() {
|
|
|
|
|
g.Starter = Card{} |
|
|
|
|
g.ThrowPile = PlayerCards{} |
|
|
|
|
g.DiscardPile = PlayerCards{} |
|
|
|
|
g.ThrownCrib1 = 0 |
|
|
|
|
g.ThrownCrib2 = 0 |
|
|
|
|
|
|
|
|
|
g.Deck = NewDeck(StandardCards, 0) |
|
|
|
|
for i := 0; i < shuffleCount; i++ { |
|
|
|
@ -154,7 +156,8 @@ func (g *Game) Cut(cut int) bool {
@@ -154,7 +156,8 @@ func (g *Game) Cut(cut int) bool {
|
|
|
|
|
if g.getClient(msgplayer).ConnType == ClientTelnet { |
|
|
|
|
g.getClient(msgplayer).write("Starter: " + g.Starter.String()) |
|
|
|
|
} else { |
|
|
|
|
g.update(msgplayer) |
|
|
|
|
//g.update(msgplayer)
|
|
|
|
|
// TODO updateAll is called
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -174,7 +177,7 @@ func (g *Game) exportJSON(player int) (string, error) {
@@ -174,7 +177,7 @@ func (g *Game) exportJSON(player int) (string, error) {
|
|
|
|
|
fieldtag := gamereflected.Type().Field(i).Tag.Get("json") |
|
|
|
|
if fieldtag == "" || fieldtag == "-" { |
|
|
|
|
continue |
|
|
|
|
} else if g.Phase != PhaseScore && (fieldname == "Hand1" && player != 1) || (fieldname == "Hand2" && player != 2) { |
|
|
|
|
} else if g.Phase != PhaseScore && ((fieldname == "Hand1" && player != 1) || (fieldname == "Hand2" && player != 2)) { |
|
|
|
|
hand := gamereflected.Field(i).Interface().(joker.Cards) |
|
|
|
|
handprinted := "" |
|
|
|
|
for j := 0; j < hand.Len(); j++ { |
|
|
|
@ -322,7 +325,7 @@ func (g *Game) scoreHands() (int, int, int) {
@@ -322,7 +325,7 @@ func (g *Game) scoreHands() (int, int, int) {
|
|
|
|
|
|
|
|
|
|
var yourscore string |
|
|
|
|
var theirscore string |
|
|
|
|
dealerscoreprinted := fmt.Sprintf("%d (%d in hand + %d in crib)", dealerHandScore+dealerCribScore, dealerHandScore, dealerCribScore) |
|
|
|
|
dealerscoreprinted := fmt.Sprintf("%d (%d hand + %d crib)", dealerHandScore+dealerCribScore, dealerHandScore, dealerCribScore) |
|
|
|
|
opponentscoreprinted := fmt.Sprintf("%d", opponentHandScore) |
|
|
|
|
for msgplayer := 1; msgplayer <= 2; msgplayer++ { |
|
|
|
|
if g.Dealer == msgplayer { |
|
|
|
@ -397,6 +400,7 @@ func (g *Game) Throw(player int, cardidentifier string) bool {
@@ -397,6 +400,7 @@ func (g *Game) Throw(player int, cardidentifier string) bool {
|
|
|
|
|
|
|
|
|
|
g.Crib = append(g.Crib, card) |
|
|
|
|
sort.Sort(g.Crib) |
|
|
|
|
|
|
|
|
|
/*if len(g.Crib.Cards) == 4 && player == g.Dealer { |
|
|
|
|
g.updateOpponent(player) |
|
|
|
|
}*/ |
|
|
|
@ -547,54 +551,52 @@ func (g *Game) updateAll() {
@@ -547,54 +551,52 @@ func (g *Game) updateAll() {
|
|
|
|
|
|
|
|
|
|
func (g *Game) printScoring() { |
|
|
|
|
for player := 1; player <= 2; player++ { |
|
|
|
|
gameprinted := []string{} |
|
|
|
|
|
|
|
|
|
opponentscore, opponentscoreresults := cribbage.Score(cribbage.ShowHand, *g.getHand(g.getOpponent(g.Dealer)), g.Starter) |
|
|
|
|
dealerscore, dealerscoreresults := cribbage.Score(cribbage.ShowHand, *g.getHand(g.Dealer), g.Starter) |
|
|
|
|
dealercribscore, dealercribscoreresults := cribbage.Score(cribbage.ShowCrib, g.Crib, g.Starter) |
|
|
|
|
var gameprinted []string |
|
|
|
|
|
|
|
|
|
dealerscoreprinted := fmt.Sprintf("%d (%d in hand + %d in crib)", dealerscore+dealercribscore, dealerscore, dealercribscore) |
|
|
|
|
opponentscoreprinted := fmt.Sprintf("%d", opponentscore) |
|
|
|
|
opponentscore, opponentscoreresults := cribbage.Score(cribbage.ShowHand, *g.getHand(g.getOpponent(player)), g.Starter) |
|
|
|
|
playerscore, dealerscoreresults := cribbage.Score(cribbage.ShowHand, *g.getHand(player), g.Starter) |
|
|
|
|
cribscore, cribscoreresults := cribbage.Score(cribbage.ShowCrib, g.Crib, g.Starter) |
|
|
|
|
|
|
|
|
|
var yourscore string |
|
|
|
|
var theirscore string |
|
|
|
|
if g.Dealer == player { |
|
|
|
|
yourscore = dealerscoreprinted |
|
|
|
|
theirscore = opponentscoreprinted |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Your hands scored %d (%d hand, %d crib) - Your opponent's hand scored %d", playerscore, cribscore, opponentscore)) |
|
|
|
|
} else { |
|
|
|
|
yourscore = opponentscoreprinted |
|
|
|
|
theirscore = dealerscoreprinted |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Your hand scored %d - Your opponent's hands scored %d (%d hand, %d crib)", playerscore, opponentscore, cribscore)) |
|
|
|
|
} |
|
|
|
|
gameprinted = append(gameprinted, "Your hand(s) scored "+yourscore+" - Your opponent's hand(s) scored "+theirscore) |
|
|
|
|
|
|
|
|
|
gameprinted = append(gameprinted, "Starter "+g.Starter.String()) |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Opponent (%2d) %s", opponentscore, g.getHand(g.getOpponent(g.Dealer)))) |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Dealer (%2d) %s", dealerscore, g.getHand(g.Dealer))) |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Dealer c. (%2d) %s", dealercribscore, g.Crib)) |
|
|
|
|
gameprinted = append(gameprinted, "Starter "+g.Starter.String()) |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Player (%2d) %s", opponentscore, g.getHand(player))) |
|
|
|
|
|
|
|
|
|
if g.Dealer == player { |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Player c. (%2d) %s", cribscore, g.Crib)) |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Opponent (%2d) %s", opponentscore, g.getHand(g.getOpponent(player)))) |
|
|
|
|
|
|
|
|
|
for _, result := range dealerscoreresults { |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Your hand scored %s", result)) |
|
|
|
|
} |
|
|
|
|
for _, result := range dealercribscoreresults { |
|
|
|
|
for _, result := range cribscoreresults { |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Your crib scored %s", result)) |
|
|
|
|
} |
|
|
|
|
for _, result := range opponentscoreresults { |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Your opponent's hand scored %s", result)) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Opponent c. (%2d) %s", cribscore, g.Crib)) |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Opponent (%2d) %s", opponentscore, g.getHand(g.getOpponent(player)))) |
|
|
|
|
|
|
|
|
|
for _, result := range opponentscoreresults { |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Your hand scored %s", result)) |
|
|
|
|
} |
|
|
|
|
for _, result := range dealerscoreresults { |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Your opponent's hand scored %s", result)) |
|
|
|
|
} |
|
|
|
|
for _, result := range dealercribscoreresults { |
|
|
|
|
for _, result := range cribscoreresults { |
|
|
|
|
gameprinted = append(gameprinted, fmt.Sprintf("Your opponent's crib scored %s", result)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
g.getClient(player).write(strings.Join(gameprinted, "\n")) |
|
|
|
|
for _, msg := range gameprinted { |
|
|
|
|
g.getClient(player).write(msg) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -879,6 +881,13 @@ func (g *Game) processGameCommand(command GameCommand) {
@@ -879,6 +881,13 @@ func (g *Game) processGameCommand(command GameCommand) {
|
|
|
|
|
g.Throw(command.Player, card) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if command.Command == CommandMessage { |
|
|
|
|
data, err := json.Marshal(command) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatal(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
g.getClient(g.getOpponent(command.Player)).write(string(data)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
g.updateAll() |
|
|
|
|