Skip to content

Instantly share code, notes, and snippets.

View ltbringer's full-sized avatar
💭
😸 I overthink so that you don't have to.

ltbringer ltbringer

💭
😸 I overthink so that you don't have to.
View GitHub Profile
@ltbringer
ltbringer / reinforcement_tic_tac_toe_snippet_6.py
Created September 3, 2018 23:25
reinforcement_tic_tac_toe_snippet_6.py
def draw_char_for_item(self, item):
"""
Returns the string mapping of the integers in the matrix
which can be understood by, but is not equal to:
{
0: ' ',
1: 'O',
2: 'X'
}
(The exact mapping is present in the constructor)
@ltbringer
ltbringer / reinforcement_tic_tac_toe_snippet_5.py
Last active September 3, 2018 23:22
reinforcement_tic_tac_toe_snippet_5.py
def have_same_val(self, axis, item, item_x, item_y):
"""
Oh boy! without the documentation this would be just 12-14 lines of code.
Checks if a row(if axis = 0) of the board matrix has same values throughout.
or
Checks if a column(if axis = 1) of the board matrix has same values throughout.
This is useful to check if a row or column is filled up by the symbol which was added the latest.
@ltbringer
ltbringer / reinforcement_tic_tac_toe_snippet_4.py
Last active September 3, 2018 22:44
reinforcement_tic_tac_toe_snippet_4.py
def element_diagonal_has_same_value(self, item, item_x, item_y):
"""
Check if any of the diagonals have same values
params
- item_x int: The row of the matrix in which item has been inserted.
- item_y int: The column of the matrix in which the item has been inserted.
- item int: The latest integer inserted into the matrix at row-index = item_x, and column-index = item_y.
"""
@ltbringer
ltbringer / reinforcement_tic_tac_toe_snippet_3.py
Created September 3, 2018 22:39
reinforcement_tic_tac_toe_snippet_3.py
def is_game_over(self, player, item, item_x, item_y):
"""
Check if the game is over, which is defined by a row, column or diagonal having
the same values as the latest inserted integer `item`.
params
- item_x int: The row of the matrix in which item has been inserted.
- item_y int: The column of the matrix in which the item has been inserted.
- item int: The latest integer inserted into the matrix at row-index = item_x, and column-index = item_y.
@ltbringer
ltbringer / reinforcement_tic_tac_toe_snippet_2.py
Last active September 3, 2018 22:34
reinforcement_tic_tac_toe_snippet_2.py
def player_move(self, input_symbol, item_x, item_y):
"""
The method which facilitates insertion of values into the board matrix.
params:
- input_symbol: 'X' or 'O'
- item_x int: The row of the matrix in which item has been inserted.
- item_y int: The column of the matrix in which the item has been inserted.
"""
@ltbringer
ltbringer / reinforcement_tic_tac_toe_snippet_1.py
Last active September 3, 2018 22:21
reinforcement_tic_tac_toe_snippet_1
def __init__(self, n=3, player_sym='x'):
"""
Constructor of the Board class, creates board objects.
- n(default=3) int: The number of rows and columns in the tic-tac-toe board.
- player_sym(default='x') str: The symbol chosen by a human player.
"""
self.board = None
self.reset_board(n)
# Initalize the board
import random
month_map = {
'january': 1,
'february': 2,
'march': 3,
'april': 4,
'may': 5,
'june': 6,
@ltbringer
ltbringer / nlg_encoder_decoder.py
Created July 26, 2017 18:36
nlg encoder decoder
import numpy as np
def char_to_vec(str_char):
byte_str = '{0:08b}'.format(ord(str_char), 'b')
return np.array([int(bit) for bit in byte_str])
def sentence_to_vec(sentence):
sentence = sentence.lower()
return np.array([char_to_vec(letter) for letter in sentence])
@ltbringer
ltbringer / usingThis.js
Last active March 6, 2017 13:40
Using this in js
/**
* Use of this in js
*
* Unlike other languages, this works a bit differently in js
* A simple way to identify what is the value of this would be:
*
*/
function someConstructor () {
this.someProperty = 1