Skip to content

Instantly share code, notes, and snippets.

View ItsMeThom-zz's full-sized avatar

Thom Lambert ItsMeThom-zz

  • Limerick, ireland
View GitHub Profile
@ItsMeThom-zz
ItsMeThom-zz / cartesian.php
Created July 7, 2017 10:30
Cartesian in PHP
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());
@ItsMeThom-zz
ItsMeThom-zz / gradient.py
Created February 16, 2018 15:59
Prototype code to generate a portion of a radial gradient (As opposed to an entire gradient) for use in masking a heighmap to be island shaped
import math
import time
chunk_size = 128;
map_width_in_chunks = 128
center_chunk = [0,0]
coordinates = [0,0]
@ItsMeThom-zz
ItsMeThom-zz / signal.py
Created January 14, 2019 09:33
Signal pattern style function callbacks
# some arbitrary functions to call
def func1():
print("called func1")
def func2():
print("called func2")
#register the methods with 'tags' tuples
dee = {
@ItsMeThom-zz
ItsMeThom-zz / statemachine.py
Created January 22, 2019 17:08
rough state machine with actions and states
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
@ItsMeThom-zz
ItsMeThom-zz / entity.py
Created January 23, 2019 16:03
Entity Component Composition tests
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
@ItsMeThom-zz
ItsMeThom-zz / ecs.py
Created January 23, 2019 16:43
signaling test
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
@ItsMeThom-zz
ItsMeThom-zz / ecs2.py
Created January 28, 2019 16:38
ECS prototype in python
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
@ItsMeThom-zz
ItsMeThom-zz / behaviour.py
Created January 29, 2019 16:31
Simple Behaviour Tree experiments python
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
@ItsMeThom-zz
ItsMeThom-zz / sudoku.py
Created February 15, 2019 16:34
Experiments with sudoku validation (Mostly playing with list comprehensions and generators)
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]
@ItsMeThom-zz
ItsMeThom-zz / Sudoku.py
Created February 18, 2019 16:34
Generate and Solve sudokupuzzles in python
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: