<commit_before>#!/usr/bin/python3
"""Base functionality for Cinch AI agents.

Method reference:

class AIBase
--identify_self()

--connect()
--poll_server()
--run_polling_loop()
--send_data(data)
--start_polling_loop()
--stop_polling_loop()

--handle_daemon_command(raw_msg)
--run()
--start()
--stop()

--handle_error(event, err_msg)
--handle_response(response)

--bid(bid)
--chat(chat_msg)
--join_game(game_id, pNum)
--play(card_val)
--request_new_game()

--decode_card(card_code)
--is_legal_bid(bid)
--is_legal_play(card)

--act()


TODO:
    - redirect print-statements elsewhere (log file?) -- pending logging
    - have 'thinking' timeout value (halt thinking after certain interval)
    --- mandate a timeout; can be a Timer call to change a loop value & publish
    --- can specify timeout in this file? want all agent models equal in this
    - if AI are allowed to use DB, impl methods here
    
"""
from _thread import start_new_thread
from time import sleep
import urllib.parse
from http.client import HTTPConnection
import json
from sys import stdin # for listening to Manager

# Settings
SERVER_HOST = ""
SERVER_PORT = 2424
SERVER_URL = "{0}:{1}".format(SERVER_HOST, SERVER_PORT)

COMET_DELAY = 3.0 # Seconds to wait between successive Comet polls
# Not currently used
THINKING_TIMEOUT = 10.0 # Secs to allow AI to think before demanding response

# Constants
EVENT_NEW_GAME = 0      # integer constants for error handling
EVENT_JOIN_GAME = 1     #
EVENT_BID = 2           #
EVENT_PLAY = 3          #

# Hardcoded values to increase performance in decoding cards
SUIT_TERMS = [0,13,26,39]
RANKS = range(2,15)

NUM_TEAMS = 2
NUM_PLAYERS = 4

GAME_UPDATE_KEYS = ['trp', 'playC', 'remP', 'sco', 'win', 'dlr', 'addC','mode']
GAMESTATE_KEYS = ['mode','trump','dealer','high_bid','declarer',
                  'previous_player','active_player','cip','scores',
                  'team_stacks']


class AIBase:
    """Common features of all Cinch AI Agents."""<commit_msg>Changed server host in base.py from "" to "localhost"<commit_after>#!/usr/bin/python3
"""Base functionality for Cinch AI agents.

Method reference:

class AIBase
--identify_self()

--connect()
--poll_server()
--run_polling_loop()
--send_data(data)
--start_polling_loop()
--stop_polling_loop()

--handle_daemon_command(raw_msg)
--run()
--start()
--stop()

--handle_error(event, err_msg)
--handle_response(response)

--bid(bid)
--chat(chat_msg)
--join_game(game_id, pNum)
--play(card_val)
--request_new_game()

--decode_card(card_code)
--is_legal_bid(bid)
--is_legal_play(card)

--act()


TODO:
    - redirect print-statements elsewhere (log file?) -- pending logging
    - have 'thinking' timeout value (halt thinking after certain interval)
    --- mandate a timeout; can be a Timer call to change a loop value & publish
    --- can specify timeout in this file? want all agent models equal in this
    - if AI are allowed to use DB, impl methods here
    
"""
from _thread import start_new_thread
from time import sleep
import urllib.parse
from http.client import HTTPConnection
import json
from sys import stdin # for listening to Manager

# Settings
SERVER_HOST = "localhost"
SERVER_PORT = 2424
SERVER_URL = "{0}:{1}".format(SERVER_HOST, SERVER_PORT)

COMET_DELAY = 3.0 # Seconds to wait between successive Comet polls
# Not currently used
THINKING_TIMEOUT = 10.0 # Secs to allow AI to think before demanding response

# Constants
EVENT_NEW_GAME = 0      # integer constants for error handling
EVENT_JOIN_GAME = 1     #
EVENT_BID = 2           #
EVENT_PLAY = 3          #

# Hardcoded values to increase performance in decoding cards
SUIT_TERMS = [0,13,26,39]
RANKS = range(2,15)

NUM_TEAMS = 2
NUM_PLAYERS = 4

GAME_UPDATE_KEYS = ['trp', 'playC', 'remP', 'sco', 'win', 'dlr', 'addC','mode']
GAMESTATE_KEYS = ['mode','trump','dealer','high_bid','declarer',
                  'previous_player','active_player','cip','scores',
                  'team_stacks']


class AIBase:
    """Common features of all Cinch AI Agents."""
{'fraction_non_alphanumeric': 0.12365725705720709, 'fraction_numerical': 0.013989507869098177, 'mean_word_length': 3.8829268292682926, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7673202', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1312, 'n_words': 395}