This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function cartesian($input) { | |
| //get cartesian product (permutations) of a nested array | |
| /* x = [ | |
| * a = [1,2], | |
| * b = [10,20,30] | |
| * ] | |
| * returns [ [1,10] , [1,20] , [1,30] , [2,10], [2,20], [2,30] ] | |
| */ | |
| $result = array(array()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| import time | |
| chunk_size = 128; | |
| map_width_in_chunks = 128 | |
| center_chunk = [0,0] | |
| coordinates = [0,0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # some arbitrary functions to call | |
| def func1(): | |
| print("called func1") | |
| def func2(): | |
| print("called func2") | |
| #register the methods with 'tags' tuples | |
| dee = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import abstractmethod, ABC | |
| class State(ABC): | |
| actions = [] # action(s) to take in this state | |
| next_states = [] # all states reachable from this state | |
| def test(self, entity): | |
| """ | |
| Perform some test using the entity data | |
| to see if this state is valid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import abstractmethod | |
| from random import randint | |
| from enum import Enum, IntEnum | |
| #Signals = Enum('Signals', ['HP_REDUCE', 'HP_INCREASE']) | |
| class Signals(IntEnum): | |
| HP_REDUCE = 0 | |
| HP_INCREASE = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import abstractmethod | |
| from random import randint | |
| from enum import Enum, IntEnum | |
| class Signals(Enum): | |
| HP_REDUCE = 0 | |
| HP_INCREASE = 1 | |
| HP_EXHAUSTED = 2 | |
| FIRE = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Entity: | |
| def __init__(self, name, *components): | |
| self.components = {} | |
| self.name = name | |
| for component in components: | |
| component.entity = self | |
| self.components[type(component)] = components | |
| def __str__(self): | |
| return self.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Tree: | |
| def __init__(self, root): | |
| self.root_node = root | |
| self.next_node = self.root_node | |
| def tick(self): | |
| print("next node is: {}".format(self.next_node)) | |
| if self.next_node is False: | |
| #TODO: Replace with enum: | |
| # Continue, Success, Failure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| board = [ | |
| [1,2,3,4,5,6,7,8,9], | |
| [5,7,8,1,3,9,6,2,4], | |
| [4,9,6,8,7,2,1,5,3], | |
| [9,5,2,3,8,1,4,6,7], | |
| [6,4,1,2,9,7,8,3,5], | |
| [3,8,7,5,6,4,2,9,1], | |
| [7,1,9,6,2,3,5,4,8], | |
| [8,6,4,9,1,5,3,7,2], | |
| [2,3,5,7,4,8,9,1,6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| from random import shuffle, sample | |
| size = 9 | |
| block_size = 3 | |
| wanted = set([x for x in range(1, size + 1)]) | |
| def create_board(): | |
| """ Create a board using the following method: |