Beispiel #1
0
    def get_legal_actions_by_tet(self, tet):
        state = GameState(self)
        q = util.Queue()
        close_set = set()
        grid,_pos = tet.spawn_tet()
        q.push(tet)
        close_set.add((_pos[0], _pos[1], tet.rotation))
        field = self.field
        length = tet.length
        minIdx = 19
        for c in range(len(field)):
            h = 19
            for i, j in enumerate(field[c]):
                if j != 0:
                    h = i - 1
                    break
            if h < minIdx:
                minIdx = h
        if minIdx - length > tet.pos[1]:
            tet.pos[1] = minIdx - length
        for i in range(minIdx - length - _pos[1]):
            tet.moving.append((0, (0, 0)))
        res = []
        while not q.isEmpty():
            cur = q.pop()

            length = cur.length
            grid = cur.grid
            all_overflow = True
            for x in range(length):
                for y in range(length):
                    if grid[x][y] == 1:
                        if cur.pos[1] + y >= 0:
                            all_overflow = False
                            break
                if not all_overflow:
                    break

            if not state.test_array(cur, (0, 1)) and not all_overflow:
                action = Action(cur)
                res.append(action)

            # expand new node
            for op in ops:
                tmp = copy.deepcopy(cur)
                kick = None
                if op == 3:
                    kick = state.test_rotate_left(tmp)
                if op == 4:
                    kick = state.test_rotate_right(tmp)
                tmp.moving.append((op, kick))
                tmp.take_op(op, kick)
                tmp_x, tmp_y = tmp.get_pos()
                p = (tmp_x, tmp_y, tmp.rotation)

                if state.test_array(tmp) and p not in close_set:
                    q.push(tmp)
                    close_set.add(p)
        return res
Beispiel #2
0
 def get_available_actions(self):
     """Find out every possible action for this instant."""
     availableActions = []
     availableActions.extend(self.get_card_play_actions())
     availableActions.extend(self.get_attack_actions())
     #availableActions.extend(heroAbilityActions)
     if len(availableActions):
         availableActions.append(Action.DoNothingAction())
     return availableActions
Beispiel #3
0
 def test_day_with_exact_year_parsed(self):
     parameters = Struct()
     parameters.update({'date': {"day": "2017-03-20", "year_exact": 1945}})
     r = Mock()
     r.action = 'history'
     r.parameters = parameters
     action = Action(r)
     self.assertEqual(action.year, "1945")
     self.assertEqual(action.date.month, 3)
     self.assertEqual(action.date.day, 20)
Beispiel #4
0
 def test_day_with_years_ago_parsed(self):
     parameters = Struct()
     parameters.update({'date': {"day": "2017-03-20", "years_ago": 75}})
     r = Mock()
     r.action = 'history'
     r.parameters = parameters
     action = Action(r)
     self.assertEqual(action.year, str(2017 - 75))
     self.assertEqual(action.date.month, 3)
     self.assertEqual(action.date.day, 20)
Beispiel #5
0
 def test_only_day_parsed(self):
     parameters = Struct()
     parameters.update({'date': {"day": "2017-03-20"}})
     r = Mock()
     r.action = 'history'
     r.parameters = parameters
     action = Action(r)
     self.assertEqual(action.date.year, 2017)
     self.assertEqual(action.date.month, 3)
     self.assertEqual(action.date.day, 20)
Beispiel #6
0
 def test_date_with_only_exact_year_parsed(self):
     parameters = Struct()
     parameters.update({'date': {
         "year_exact": 1910,
     }})
     r = Mock()
     r.action = 'history'
     r.parameters = parameters
     action = Action(r)
     self.assertEqual(action.year, "1910")
     self.assertEqual(action.date.month, date.today().month)
     self.assertEqual(action.date.day, date.today().day)
Beispiel #7
0
 def get_attack_actions(self):
     """Find all possible attack combinations and return a list of them."""
     actionList = []
     potentialAttackers = self.get_canAttack_characters()
     if not len(potentialAttackers):
         return []
     for character in potentialAttackers:
         potentialTargets = self.get_targetable_characters(character)
         if not len(potentialTargets):
             continue
         for target in potentialTargets:
             actionList.append(Action.AttackAction(character, target))
     return actionList
Beispiel #8
0
 def test_exact_day_parsed(self, dt):
     today = Mock()
     today().year = 2014
     dt.today = today
     parameters = Struct()
     parameters.update({'date': {"day": "2015-03-20"}})
     r = Mock()
     r.action = 'history'
     r.parameters = parameters
     action = Action(r)
     self.assertEqual(action.date.year, 2015)
     self.assertEqual(action.date.month, 3)
     self.assertEqual(action.date.day, 20)
Beispiel #9
0
    def get_card_play_actions(self):
        actionList = []
        playableCards = self.get_hand().get_playable_cards()
        if not len(playableCards):
            return []
        emptyPositions = self.get_empty_minion_positions()

        for card in playableCards:
            # Create actions for dropping a minion.
            if isinstance(card.contents, Character) and len(emptyPositions):
                #for pos in emptyPositions:
                #    actionList.append(Action.PlayMinionAction(card, self.get_side(), pos))
                actionList.append(
                    Action.PlayMinionAction(card, self.get_side(),
                                            emptyPositions[0])
                )  # Always play in the first empty spot.

            # Create actions for using a spell
            elif isinstance(card.contents, Spell):
                actionList.append(Action.PlaySpellAction(card))

            # Create actions for equipping a weapon.

        return actionList
Beispiel #10
0
from ai import AI, Action
from services import Services
from dbcall import Dtbase
import os

services = Services()
ai = AI()
action = Action()
db = Dtbase()

if __name__ == "__main__":
    loginsuccess = action.dbCheck()
    if loginsuccess == True:
        while True:
            query = ai.takeCommand().lower()

            if "time" in query:
                services.clock()
            elif 'date' in query:
                services.date()
            elif 'search wikipedia for' in query:
                services.wikisearch(query)
            elif 'search in chrome' in query:
                services.chromesearch()
            elif 'send mail' in query:
                services.mailService()
            elif query.startswith('remember'):
                db.remember(query.replace('remember', ''))
            elif 'lock' in query:
                os.system('shutdown -l')
            elif 'shutdown' in query: