<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tile as t
import fp   as f

########################
### Class Definition ###
########################

h1 = [ ('C', 7), ('C', 8), ('C', 9)
     , ('W', 1), ('W', 1), ('W', 1)
     , ('K', 1), ('K', 2), ('K', 3)
     , ('B', 4), ('B', 5), ('B', 6)
     , ('D', 1), ('D', 1)
     ]


h2 = { 'concealed': [ [ ('B', 4), ('B', 5), ('B', 6) ]
                    , [ ('D', 1), ('D', 1) ]
                    ]
     , 'melded': [ [ ('C', 7), ('C', 8), ('C', 9) ]
                 , [ ('W', 1), ('W', 1), ('W', 1) ]
                 , [ ('K', 1), ('K', 2), ('K', 3) ]
                 ]
     , 'bonus': [ ('F', 1), ('S', 2) ]
     }

h_A_seq = { 'concealed': [ [ ('B', 4), ('B', 5), ('B', 6) ]
                         , [ ('D', 1), ('D', 1) ]
                         ]
          , 'melded': [ [ ('C', 7), ('C', 8), ('C', 9) ]
                      , [ ('B', 2), ('B', 3), ('B', 4) ]
                      , [ ('K', 1), ('K', 2), ('K', 3) ]
                      ]
          , 'bonus': [ ('F', 1), ('S', 2) ]
          }


# leave this for now, should just delete it later since we are not doing OO
class Hand:

    _concealed = None
    _melded    = None
    _bonus     = None

    def __init__(self, concealed, melded, bonus):
        if tiles is not None:
            self._concealed = concealed
            self._melded    = melded
            self._bonus     = bonus

    @property
    def concealed(self):
        return self._concealed

    @property
    def melded(self):
        return self._melded

    @property
    def bonus(self):
        return self._bonus

    def as_dict(self):
        return { 'concealed' : self._concealed
               , 'melded'    : self._melded
               , 'bonus'     : self._bonus
               }

# def sort_hand(hand):
#     return Hand( sorted(hand.tiles, cmp=tile.compare) )

def sort_tiles(tiles):
    return f.sort_by(t.compare, tiles)


#############
### Melds ###
#############


# only checks if its a 3 or 4 set to distinguish it from eyes
def is_meld(tiles):
    return 3 <= len(tiles) <= 4

def is_terminal_meld(tiles):
    pass

def is_honor_meld(tiles):
    pass

def is_chow(tiles):
    if len(tiles) == 3:
        meld = sort_tiles(tiles)
        suits = f.map_func(t.fst, meld)
        if suits[0] == suits[1] == suits[2]:
            values = f.map_func(t.snd, meld)
            if values[0] + 2 == values[1] + 1 == values[2]:
                return True
    return False

def is_terminal_chow(tiles):
    if len(tiles) == 3:
        meld = sort_tiles(tiles)
        suits = f.map_func(t.fst, meld)
        if suits[0] == suits[1] == suits[2]:
            values = f.map_func(t.snd, meld)
            if values[0] + 2 == values[1] + 1 == values[2]:
                if values[0] == 1 or values[2] == 3:
                    return True
    return False

def is_simple_chow(tiles):
    if len(tiles) == 3:
        meld = sort_tiles(tiles)
        suits = f.map_func(t.fst, meld)
        if suits[0] == suits[1] == suits[2]:
            values = f.map_func(t.snd, meld)
            if values[0] + 2 == values[1] + 1 == values[2]:
                if values[0] != 1 or values[2] != 9:
                    return True
    return False


def is_pung(tiles):
    if len(tiles) == 3:
        if tiles[0] == tiles[1] == tiles[2]:
            return True
    return False


def is_kong(tiles):
    if len(tiles) == 4:
        if tiles[0] == tiles[1] == tiles[2] == tiles[3]:
            return True
    return False

def is_eye(tiles):
    if len(tiles) == 2:
        if tile.fst(tiles) == tile.snd(tiles):
            return True
    return False



########################
### Hand evaluations ###
########################<commit_msg>added terminal pung check<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tile as t
import fp   as f

########################
### Class Definition ###
########################

h1 = [ ('C', 7), ('C', 8), ('C', 9)
     , ('W', 1), ('W', 1), ('W', 1)
     , ('K', 1), ('K', 2), ('K', 3)
     , ('B', 4), ('B', 5), ('B', 6)
     , ('D', 1), ('D', 1)
     ]


h2 = { 'concealed': [ [ ('B', 4), ('B', 5), ('B', 6) ]
                    , [ ('D', 1), ('D', 1) ]
                    ]
     , 'melded': [ [ ('C', 7), ('C', 8), ('C', 9) ]
                 , [ ('W', 1), ('W', 1), ('W', 1) ]
                 , [ ('K', 1), ('K', 2), ('K', 3) ]
                 ]
     , 'bonus': [ ('F', 1), ('S', 2) ]
     }

h_A_seq = { 'concealed': [ [ ('B', 4), ('B', 5), ('B', 6) ]
                         , [ ('D', 1), ('D', 1) ]
                         ]
          , 'melded': [ [ ('C', 7), ('C', 8), ('C', 9) ]
                      , [ ('B', 2), ('B', 3), ('B', 4) ]
                      , [ ('K', 1), ('K', 2), ('K', 3) ]
                      ]
          , 'bonus': [ ('F', 1), ('S', 2) ]
          }


# leave this for now, should just delete it later since we are not doing OO
class Hand:

    _concealed = None
    _melded    = None
    _bonus     = None

    def __init__(self, concealed, melded, bonus):
        if tiles is not None:
            self._concealed = concealed
            self._melded    = melded
            self._bonus     = bonus

    @property
    def concealed(self):
        return self._concealed

    @property
    def melded(self):
        return self._melded

    @property
    def bonus(self):
        return self._bonus

    def as_dict(self):
        return { 'concealed' : self._concealed
               , 'melded'    : self._melded
               , 'bonus'     : self._bonus
               }

# def sort_hand(hand):
#     return Hand( sorted(hand.tiles, cmp=tile.compare) )

def sort_tiles(tiles):
    return f.sort_by(t.compare, tiles)


#############
### Melds ###
#############


# only checks if its a 3 or 4 set to distinguish it from eyes
def is_meld(tiles):
    return 3 <= len(tiles) <= 4

def is_terminal_meld(tiles):
    pass

def is_honor_meld(tiles):
    pass

def is_chow(tiles):
    if len(tiles) == 3:
        meld = sort_tiles(tiles)
        suits = f.map_func(t.fst, meld)
        if suits[0] == suits[1] == suits[2]:
            values = f.map_func(t.snd, meld)
            if values[0] + 2 == values[1] + 1 == values[2]:
                return True
    return False

def is_terminal_chow(tiles):
    if len(tiles) == 3:
        meld = sort_tiles(tiles)
        suits = f.map_func(t.fst, meld)
        if suits[0] == suits[1] == suits[2]:
            values = f.map_func(t.snd, meld)
            if values[0] + 2 == values[1] + 1 == values[2]:
                if values[0] == 1 or values[2] == 3:
                    return True
    return False

def is_simple_chow(tiles):
    if len(tiles) == 3:
        meld = sort_tiles(tiles)
        suits = f.map_func(t.fst, meld)
        if suits[0] == suits[1] == suits[2]:
            values = f.map_func(t.snd, meld)
            if values[0] + 2 == values[1] + 1 == values[2]:
                if values[0] != 1 or values[2] != 9:
                    return True
    return False


def is_pung(tiles):
    if len(tiles) == 3:
        if tiles[0] == tiles[1] == tiles[2]:
            return True
    return False

def is_terminal_pung(tiles):
    if len(tiles) == 3:
        if tiles[0] == tiles[1] == tile[2]:
            if f.or_func( f.map_func(t.is_edge, tiles) ):
                return True
    return False


is_ is_kong(tiles):
    if len(tiles) == 4:
        if tiles[0] == tiles[1] == tiles[2] == tiles[3]:
            return True
    return False

def is_eye(tiles):
    if len(tiles) == 2:
        if tile.fst(tiles) == tile.snd(tiles):
            return True
    return False



########################
### Hand evaluations ###
########################
{'fraction_non_alphanumeric': 0.21002201217143596, 'fraction_numerical': 0.025896672277612328, 'mean_word_length': 1.7360963513992207, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4357742', 'n_tokens_mistral': 2908, 'n_tokens_neox': 2706, 'n_words': 720}