<commit_before>package blackjack

import (
	"fmt"
	"github.com/jkomoros/boardgame"
	"strings"
)

type mainState struct {
	Game    *gameState
	Players []*playerState
}

type gameState struct {
	DiscardStack  *boardgame.GrowableStack
	DrawStack     *boardgame.GrowableStack
	UnusedCards   *boardgame.GrowableStack
	CurrentPlayer int
}

type playerState struct {
	playerIndex int
	Hand        *boardgame.GrowableStack
	Busted      bool
	Stood       bool
}

func (g *gameState) Props() []string {
	return boardgame.PropertyReaderPropsImpl(g)
}

func (g *gameState) Prop(name string) interface{} {
	return boardgame.PropertyReaderPropImpl(g, name)
}

func (g *gameState) Copy() boardgame.GameState {
	var result gameState
	result = *g
	return &result
}

func (p *playerState) Props() []string {
	return boardgame.PropertyReaderPropsImpl(p)
}

func (p *playerState) Prop(name string) interface{} {
	return boardgame.PropertyReaderPropImpl(p, name)
}

func (p *playerState) Copy() boardgame.PlayerState {
	var result playerState
	result = *p
	return &result
}

func (p *playerState) PlayerIndex() int {
	return p.playerIndex
}

//HandValue returns the value of the player's hand.
func (p *playerState) HandValue() int {

	var numUnconvertedAces int
	var currentValue int

	for _, card := range cards(p.Hand.ComponentValues()) {
		switch card.Rank {
		case RankAce:
			numUnconvertedAces++
			//We count the ace as 1 now. Later we'll check to see if we can
			//expand any aces.
			currentValue += 1
		case RankJack, RankQueen, RankKing:
			currentValue += 10
		default:
			currentValue += int(card.Rank)
		}
	}

	for numUnconvertedAces > 0 {

		if currentValue >= (targetScore - 10) {
			break
		}

		numUnconvertedAces--
		currentValue += 10
	}

	return currentValue

}

func (m *mainState) Diagram() string {
	var result []string

	result = append(result, fmt.Sprintf("Cards left in deck: %d", m.Game.DrawStack.NumComponents()))

	for i, player := range m.Players {
		result = append(result, fmt.Sprintf("Player %d", i))

		statusLine := fmt.Sprintf("\tValue: %d", player.HandValue())

		if player.Busted {
			statusLine += " BUSTED"
		}

		if player.Stood {
			statusLine += " STOOD"
		}

		result = append(result, statusLine)

		result = append(result, "\tCards:")

		for _, card := range cards(player.Hand.ComponentValues()) {
			result = append(result, "\t\t"+card.String())
		}

		result = append(result, "")
	}

	return strings.Join(result, "\n")
}

func (s *mainState) GameState() boardgame.GameState {
	return s.Game
}

func (s *mainState) PlayerStates() []boardgame.PlayerState {
	array := make([]boardgame.PlayerState, len(s.Players))

	for i := 0; i < len(s.Players); i++ {
		array[i] = s.Players[i]
	}

	return array
}

func (s *mainState) Copy() boardgame.State {
	array := make([]*playerState, len(s.Players))

	for i := 0; i < len(s.Players); i++ {
		array[i] = s.Players[i].Copy().(*playerState)
	}

	return &mainState{
		Game:    s.Game.Copy().(*gameState),
		Players: array,
	}
}
<commit_msg>In blackjack diagram, mark which player is the current player. part of #16.<commit_after>package blackjack

import (
	"fmt"
	"github.com/jkomoros/boardgame"
	"strings"
)

type mainState struct {
	Game    *gameState
	Players []*playerState
}

type gameState struct {
	DiscardStack  *boardgame.GrowableStack
	DrawStack     *boardgame.GrowableStack
	UnusedCards   *boardgame.GrowableStack
	CurrentPlayer int
}

type playerState struct {
	playerIndex int
	Hand        *boardgame.GrowableStack
	Busted      bool
	Stood       bool
}

func (g *gameState) Props() []string {
	return boardgame.PropertyReaderPropsImpl(g)
}

func (g *gameState) Prop(name string) interface{} {
	return boardgame.PropertyReaderPropImpl(g, name)
}

func (g *gameState) Copy() boardgame.GameState {
	var result gameState
	result = *g
	return &result
}

func (p *playerState) Props() []string {
	return boardgame.PropertyReaderPropsImpl(p)
}

func (p *playerState) Prop(name string) interface{} {
	return boardgame.PropertyReaderPropImpl(p, name)
}

func (p *playerState) Copy() boardgame.PlayerState {
	var result playerState
	result = *p
	return &result
}

func (p *playerState) PlayerIndex() int {
	return p.playerIndex
}

//HandValue returns the value of the player's hand.
func (p *playerState) HandValue() int {

	var numUnconvertedAces int
	var currentValue int

	for _, card := range cards(p.Hand.ComponentValues()) {
		switch card.Rank {
		case RankAce:
			numUnconvertedAces++
			//We count the ace as 1 now. Later we'll check to see if we can
			//expand any aces.
			currentValue += 1
		case RankJack, RankQueen, RankKing:
			currentValue += 10
		default:
			currentValue += int(card.Rank)
		}
	}

	for numUnconvertedAces > 0 {

		if currentValue >= (targetScore - 10) {
			break
		}

		numUnconvertedAces--
		currentValue += 10
	}

	return currentValue

}

func (m *mainState) Diagram() string {
	var result []string

	result = append(result, fmt.Sprintf("Cards left in deck: %d", m.Game.DrawStack.NumComponents()))

	for i, player := range m.Players {

		playerLine := fmt.Sprintf("Player %d", i)

		if i == m.Game.CurrentPlayer {
			playerLine += "  *CURRENT*"
		}

		result = append(result, playerLine)

		statusLine := fmt.Sprintf("\tValue: %d", player.HandValue())

		if player.Busted {
			statusLine += " BUSTED"
		}

		if player.Stood {
			statusLine += " STOOD"
		}

		result = append(result, statusLine)

		result = append(result, "\tCards:")

		for _, card := range cards(player.Hand.ComponentValues()) {
			result = append(result, "\t\t"+card.String())
		}

		result = append(result, "")
	}

	return strings.Join(result, "\n")
}

func (s *mainState) GameState() boardgame.GameState {
	return s.Game
}

func (s *mainState) PlayerStates() []boardgame.PlayerState {
	array := make([]boardgame.PlayerState, len(s.Players))

	for i := 0; i < len(s.Players); i++ {
		array[i] = s.Players[i]
	}

	return array
}

func (s *mainState) Copy() boardgame.State {
	array := make([]*playerState, len(s.Players))

	for i := 0; i < len(s.Players); i++ {
		array[i] = s.Players[i].Copy().(*playerState)
	}

	return &mainState{
		Game:    s.Game.Copy().(*gameState),
		Players: array,
	}
}

{'fraction_non_alphanumeric': 0.1325769854132901, 'fraction_numerical': 0.0038897893030794164, 'mean_word_length': 3.847604084838963, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '330372', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2117, 'n_words': 561}