Example #1
0
 def __init__(self):
     '''
     Constructor
     '''
     self._keywords = ["BEGIN", "DO", "ELSE", "END", "INSTRUCTION",
                  "IF", "IS", "PROGRAM", "THEN", "WHILE"]
     self._conditions = ["next-is-empty", "next-is-not-empty",
                  "next-is-enemy", "next-is-not-enemy",
                  "next-is-friend", "next-is-not-friend",
                  "next-is-wall", "next-is-not-wall",
                  "random", "true"]
     self._states = enum("EMPTY", "ERROR", "WHITESPACE", "COND_KEY_ID",
                         "COMMENT")
     self._types = enum("ERROR", "WHITESPACE", "CONDITION", "KEYWORD",
                        "IDENTIFIER", "COMMENT")
     self._buffer = ""
     self._bufferState = self._states.EMPTY
     self._readyToDispense = 0
Example #2
0
 def __init__(self):
     '''
     Constructor
     '''
     self._keywords = [
         "BEGIN", "DO", "ELSE", "END", "INSTRUCTION", "IF", "IS", "PROGRAM",
         "THEN", "WHILE"
     ]
     self._conditions = [
         "next-is-empty", "next-is-not-empty", "next-is-enemy",
         "next-is-not-enemy", "next-is-friend", "next-is-not-friend",
         "next-is-wall", "next-is-not-wall", "random", "true"
     ]
     self._states = enum("EMPTY", "ERROR", "WHITESPACE", "COND_KEY_ID",
                         "COMMENT")
     self._types = enum("ERROR", "WHITESPACE", "CONDITION", "KEYWORD",
                        "IDENTIFIER", "COMMENT")
     self._buffer = ""
     self._bufferState = self._states.EMPTY
     self._readyToDispense = 0
Example #3
0
'''
Created on Nov 7, 2011

@author: Calvin
'''

from Enum import enum
import sys

WIDTH = 20
HEIGHT = 20

_grid = [[0 for row in range(WIDTH)] for col in range(HEIGHT)]

states = enum("EMPTY", "ENEMY", "FRIEND", "WALL")


def get_pos(pos):
    '''
    Returns empty, wall, or a reference to the bug at the given position.
    '''
    if pos[0] < 0 or pos[1] < 0 or pos[0] > HEIGHT - 1 or pos[1] > WIDTH - 1:
        return states.WALL
    else:
        return _grid[pos[0]][pos[1]]


def set_pos(pos, bug):
    '''
    Sets the given position in the grid.
    '''
Example #4
0
"""
Created on Nov 7, 2011

@author: Calvin
"""

from Enum import enum
import sys

WIDTH = 20
HEIGHT = 20

_grid = [[0 for row in range(WIDTH)] for col in range(HEIGHT)]

states = enum("EMPTY", "ENEMY", "FRIEND", "WALL")


def get_pos(pos):
    """
    Returns empty, wall, or a reference to the bug at the given position.
    """
    if pos[0] < 0 or pos[1] < 0 or pos[0] > HEIGHT - 1 or pos[1] > WIDTH - 1:
        return states.WALL
    else:
        return _grid[pos[0]][pos[1]]


def set_pos(pos, bug):
    """
    Sets the given position in the grid.
    """
Example #5
0
# from enum import Enum
from Enum import enum as enum
# class UserStatus(Enum):
#
#     USER_INVITED = 0
#     USER_AWAITING_TURN = 1
#     USER_TURN = 2
#     USER_MATCH_COMPLETED = 3

UserStatus = enum(
    USER_INVITED='USER_INVITED',
    USER_AWAITING_TURN='USER_AWAITING_TURN',
    USER_TURN='USER_TURN',
    USER_MATCH_COMPLETED='USER_MATCH_COMPLETED',
)
Example #6
0
'''
Created on Nov 1, 2011

@author: Calvin
'''

from Enum import enum

_conditions_text = [
    "next-is-empty", "next-is-not-empty", "next-is-enemy", "next-is-not-enemy",
    "next-is-friend", "next-is-not-friend", "next-is-wall", "next-is-not-wall",
    "random", "true"
]
_kinds = enum("WHILE", "IF", "IFELSE", "CALL", "BLOCK")
_types = enum("ERROR", "WHITESPACE", "CONDITION", "KEYWORD", "IDENTIFIER",
              "COMMENT")
_calls = ["infect", "move", "skip", "turnright", "turnleft"]

codes = enum("MOVE", "TURNLEFT", "TURNRIGHT", "INFECT", "SKIP", "HALT", "JUMP",
             "JUMP_IF_NOT_NEXT_IS_EMPTY", "JUMP_IF_NOT_NEXT_IS_NOT_EMPTY",
             "JUMP_IF_NOT_NEXT_IS_ENEMY", "JUMP_IF_NOT_NEXT_IS_NOT_ENEMY",
             "JUMP_IF_NOT_NEXT_IS_FRIEND", "JUMP_IF_NOT_NEXT_IS_NOT_FRIEND",
             "JUMP_IF_NOT_NEXT_IS_WALL", "JUMP_IF_NOT_NEXT_IS_NOT_WALL",
             "JUMP_IF_NOT_RANDOM", "JUMP_IF_NOT_TRUE", "RETURN",
             "JUMP_TO_INSTR")
Example #7
0
File: Bug.py Project: Unilat/bugs
'''
Created on Nov 4, 2011

@author: Calvin
'''

import Constants
from random import randint
from Enum import enum
from Debug import debug
import Grid

_facing = enum("UP", "DOWN", "LEFT", "RIGHT")

class Bug(object):
    '''
    Represents one Bug game object with PC and stack for code execution.
    '''

    def __init__(self, pos, facing, team):
        '''
        Constructor takes a starting pc and a reference to code array.
        '''
        self.team = team
        self._pc = team.bugCode[0]
        self._code = team.bugCode
        self._stack = []
        self._pos = pos
        self._direction = facing
        
        # Indicate where we've placed the bug is taken
Example #8
0
File: Bug.py Project: Calpoog/bugs
'''
Created on Nov 4, 2011

@author: Calvin
'''

import Constants
from random import randint
from Enum import enum
from Debug import debug
import Grid

_facing = enum("UP", "DOWN", "LEFT", "RIGHT")


class Bug(object):
    '''
    Represents one Bug game object with PC and stack for code execution.
    '''
    def __init__(self, pos, facing, team):
        '''
        Constructor takes a starting pc and a reference to code array.
        '''
        self.team = team
        self._pc = team.bugCode[0]
        self._code = team.bugCode
        self._stack = []
        self._pos = pos
        self._direction = facing

        # Indicate where we've placed the bug is taken
Example #9
0
# from enum import Enum
#
#
# class MatchResult(Enum):
#
#     MATCH_RESULT_WIN = 0
#     MATCH_RESULT_LOSS = 1
#     MATCH_RESULT_TIE = 2
#     MATCH_RESULT_NONE = 3
#     MATCH_RESULT_DISCONNECT = 4
#     MATCH_RESULT_DISAGREED = 5

from Enum import enum as enum

MatchResult= enum(MATCH_RESULT_WIN='MATCH_RESULT_WIN',
                   MATCH_RESULT_LOSS='MATCH_RESULT_LOSS',
                   MATCH_RESULT_TIE='MATCH_RESULT_TIE',
                   MATCH_RESULT_NONE='MATCH_RESULT_NONE',
                   MATCH_RESULT_DISCONNECT='MATCH_RESULT_DISCONNECT',
                   MATCH_RESULT_DISAGREED='MATCH_RESULT_DISAGREED')
Example #10
0
'''
Created on Nov 1, 2011

@author: Calvin
'''

from Enum import enum

_conditions_text = ["next-is-empty", "next-is-not-empty",
           "next-is-enemy", "next-is-not-enemy",
           "next-is-friend", "next-is-not-friend",
           "next-is-wall", "next-is-not-wall",
           "random", "true"]
_kinds = enum("WHILE", "IF", "IFELSE", "CALL", "BLOCK")
_types = enum("ERROR", "WHITESPACE", "CONDITION", "KEYWORD",
              "IDENTIFIER", "COMMENT")
_calls = ["infect", "move", "skip", "turnright", "turnleft"]

codes = enum("MOVE", "TURNLEFT", "TURNRIGHT", "INFECT",
                "SKIP", "HALT", "JUMP", "JUMP_IF_NOT_NEXT_IS_EMPTY",
                "JUMP_IF_NOT_NEXT_IS_NOT_EMPTY", "JUMP_IF_NOT_NEXT_IS_ENEMY",
                "JUMP_IF_NOT_NEXT_IS_NOT_ENEMY", "JUMP_IF_NOT_NEXT_IS_FRIEND",
                "JUMP_IF_NOT_NEXT_IS_NOT_FRIEND", "JUMP_IF_NOT_NEXT_IS_WALL",
                "JUMP_IF_NOT_NEXT_IS_NOT_WALL", "JUMP_IF_NOT_RANDOM",
                "JUMP_IF_NOT_TRUE", "RETURN", "JUMP_TO_INSTR")
Example #11
0
#
# from enum import Enum
#
#
# class ParticipantStatus(Enum):
#
#     PARTICIPANT_NOT_INVITED_YET = 0
#     PARTICIPANT_INVITED = 1
#     PARTICIPANT_JOINED = 2
#     PARTICIPANT_DECLINED = 3
#     PARTICIPANT_LEFT = 4
#     PARTICIPANT_FINISHED = 5
#     PARTICIPANT_UNRESPONSIVE = 6

from Enum import enum as enum

ParticipantStatus = enum(
    PARTICIPANT_NOT_INVITED_YET='PARTICIPANT_NOT_INVITED_YET',
    PARTICIPANT_INVITED='PARTICIPANT_INVITED',
    PARTICIPANT_JOINED='PARTICIPANT_JOINED',
    PARTICIPANT_DECLINED='PARTICIPANT_DECLINED',
    PARTICIPANT_LEFT='PARTICIPANT_LEFT',
    PARTICIPANT_FINISHED='PARTICIPANT_FINISHED',
    PARTICIPANT_UNRESPONSIVE='PARTICIPANT_UNRESPONSIVE')
Example #12
0
from Enum import enum as enum


# def enum(**enums):
#     return type('Enum', (), enums)

MatchStatus = enum(MATCH_AUTO_MATCHING='MATCH_AUTO_MATCHING',
                   MATCH_ACTIVE='MATCH_ACTIVE',
                   MATCH_COMPLETE='MATCH_COMPLETE',
                   MATCH_EXPIRED='MATCH_EXPIRED',
                   MATCH_DELETED='MATCH_DELETED')

#
# class MatchStatus(Enum):
#
#     MATCH_AUTO_MATCHING = 0
#     MATCH_ACTIVE = 1
#     MATCH_COMPLETE = 2
#     MATCH_CANCELLED = 3
#     MATCH_EXPIRED = 4
#     MATCH_DELETED = 5
#
#     def __str__(self):
#         if self.value == 0:
#             return 'MATCH_AUTO_MATCHING'