<commit_before>package main

import (
	"fmt"
	"sort"
)

// Hand is the array of cards a player is holding. Max hand size will be ten card.
type Hand []Card

// ByValue container for cards sorted by value.
type ByValue Hand

// BySuit container for cards sorted by suit.
type BySuit Hand

// PickUpAble describes a type that can add a card to player's hand. These
// types are Deck and Stack.
type PickUpAble interface {
	Len() int
	Pop() Card
	DrawCard() Card
}

// ByValue implemented by Sort
func (hand ByValue) Len() int {
	return len(hand)
}
func (hand ByValue) Less(i, j int) bool {
	return hand[i].value < hand[j].value
}
func (hand ByValue) Swap(i, j int) {
	hand[i], hand[j] = hand[j], hand[i]
}

// BySuit implemented by Sort
func (hand BySuit) Len() int {
	return len(hand)
}
func (hand BySuit) Less(i, j int) bool {
	return hand[i].suit < hand[j].suit
}
func (hand BySuit) Swap(i, j int) {
	hand[i], hand[j] = hand[j], hand[i]
}

func (s *Stack) Len() int {
	return len(*s)
}

func (d *Deck) Len() int {
	return len(*d)
}

func (s *Stack) Pop() Card {
	return (*s)[:len(*s)-1], (*s)[len(*s)]
}

// PrettyPrint a player's hand. This is for the view.
func (hand Hand) PrettyPrint() (result string) {
	// First sort Cards then pretty print
	sort.Sort(ByValue(hand))
	for i, card := range hand {
		result += card.symbol + card.suit[:1]
		if i != len(hand)-1 {
			result += " "
		}
	}
	return
}

// String() allows us to pretty print everytime we pass it to fmt.Print.
func (hand *Hand) String() string {
	return hand.PrettyPrint()
}

// CheckTotal checks the total number of points in a player's hand. It must be // less than 10 to knock.
func (hand *Hand) CheckTotal() (total int) {
	hand.CheckMeld()
	// for i, card := range *hand {

	// }
	return
}

// CheckMeld checks the melds that can be made in the player's hand. There may // be more than one meld configuration for various hands.
func (hand *Hand) CheckMeld() Hand {
	sort.Sort(ByValue(*hand))
	sort.Sort(BySuit(*hand))
	return *hand
}

// DrawCard by popping a card from a pickupable and appending it to a player's hand.
func (hand *Hand) DrawCard(pickupable PickUpAble) (d *PickUpAble, err error) {
	p := pickupable
	if len(*hand) >= 11 {
		err = fmt.Errorf("cannot have a hand size more than 11")
		return
	}
	card := p.Len()
	p = p[:len(p)-1]
	*hand = append(*hand, card)
	return
}

// DiscardCard places a card on top of the stack.
func (hand *Hand) DiscardCard(stack *Stack) (err error) {
	return
}
<commit_msg>FIxed draw and discard from hand.<commit_after>package main

import (
	"fmt"
	"sort"
)

// Hand is the array of cards a player is holding. Max hand size will be ten card.
type Hand []Card

// ByValue container for cards sorted by value.
type ByValue Hand

// BySuit container for cards sorted by suit.
type BySuit Hand

// PickUpAble describes a type that can add a card to player's hand. These
// types are Deck and Stack.
type PickUpAble interface {
	DrawCard() Card
}

// ByValue implemented by Sort
func (hand ByValue) Len() int {
	return len(hand)
}
func (hand ByValue) Less(i, j int) bool {
	return hand[i].value < hand[j].value
}
func (hand ByValue) Swap(i, j int) {
	hand[i], hand[j] = hand[j], hand[i]
}

// BySuit implemented by Sort
func (hand BySuit) Len() int {
	return len(hand)
}
func (hand BySuit) Less(i, j int) bool {
	return hand[i].suit < hand[j].suit
}
func (hand BySuit) Swap(i, j int) {
	hand[i], hand[j] = hand[j], hand[i]
}

func (s *Stack) Len() int {
	return len(*s)
}

func (d *Deck) Len() int {
	return len(*d)
}

func (s *Stack) Pop() Card {
	return (*s)[:len(*s)-1], (*s)[len(*s)]
}

// PrettyPrint a player's hand. This is for the view.
func (h Hand) PrettyPrint() (result string) {
	// First sort Cards then pretty print
	sort.Sort(ByValue(h))
	for i, card := range h {
		result += card.symbol + card.suit[:1]
		if i != len(h)-1 {
			result += " "
		}
	}
	return
}

// String() allows us to pretty print everytime we pass it to fmt.Print.
func (h *Hand) String() string {
	return h.PrettyPrint()
}

// CheckTotal checks the total number of points in a player's hand. It must be // less than 10 to knock.
func (h *Hand) CheckTotal() (total int) {
	h.CheckMeld()
	// for i, card := range *hand {

	// }
	return
}

// CheckMeld checks the melds that can be made in the player's hand. There may // be more than one meld configuration for various hands.
func (h *Hand) CheckMeld() Hand {
	sort.Sort(ByValue(*h))
	sort.Sort(BySuit(*h))
	return *h
}

// DrawCard by popping a card from a pickupable and appending it to a player's hand.
func (h *Hand) DrawCard(p *PickUpAble) (err error) {
	if len(*h) >= 11 {
		err = fmt.Errorf("cannot have a hand size more than 11")
		return
	}
	*h = append(*h, (*p).DrawCard())
	return
}

// DiscardCard places a card on top of the stack.
func (h *Hand) DiscardCard(card Card, stack *Stack) (err error) {
	for i, v := range *h {
		if card == v {
			*h = append((*h)[:i], (*h)[i+1:]...)
			*stack = append((*stack), card)
		}
	}
	return
}

{'fraction_non_alphanumeric': 0.14325842696629212, 'fraction_numerical': 0.0040128410914927765, 'mean_word_length': 3.4390026714158504, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1702027', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1787, 'n_words': 685}