This file contains 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
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) |
This file contains 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
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. |
This file contains 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
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. | |
""" |
This file contains 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
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. |
This file contains 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
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. | |
""" |
This file contains 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
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 |
This file contains 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 random | |
month_map = { | |
'january': 1, | |
'february': 2, | |
'march': 3, | |
'april': 4, | |
'may': 5, | |
'june': 6, |
This file contains 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 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]) |
This file contains 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
/** | |
* 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 |
NewerOlder