Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
PLAYER_1 = 1 PLAYER_2 = 2 class NoughtsAndCrosses(object): """Basic implementation of Noughts and Crosses""" WIN_COMBOS = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]] EMPTY_BOARD = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] def __init__(self): self.current_board = self.EMPTY_BOARD.copy() self.current_player = PLAYER_1 # game always starts with PLAYER_1 self.player_names = {} self.player_markers = { PLAYER_1: "", PLAYER_2: "", } def _print_board(self): """Prints the current board""" print("--- Noughts and Crosses ---") print(f'{self.current_board[0]} : {self.current_board[1]} : {self.current_board[2]}') print("..........") print(f'{self.current_board[3]} : {self.current_board[4]} : {self.current_board[5]}') print("..........") print(f'{self.current_board[6]} : {self.current_board[7]} : {self.current_board[8]}') def play(self): self._print_welcome_message() self._get_player_names() self._get_player_markers() while True: self._let_current_player_move() if self._player_has_won(self.current_player): print(f"{self.player_names[self.current_player]}, you have won!") break elif self._check_if_board_is_full(): print(f"Stalemate - End of game") break self._switch_current_player() def _let_current_player_move(self): print("Hi", self.player_names[self.current_player]) while True: chosen_board_index = self._get_next_move() if self._location_is_taken(chosen_board_index): print('>>> Position taken, try again!') continue else: self._update_board(chosen_board_index) self._print_board() break def _update_board(self, chosen_board_index): self.current_board[chosen_board_index] = self.player_markers[self.current_player] @staticmethod def _print_welcome_message(): print("*" * 50) print("Welcome to our Noughts and Crosses Game!") print("*" * 50) def _get_player_names(self): self.player_names[1] = input("Enter the name of the first player:\n> ") self.player_names[2] = input("Enter the name of the second player:\n> ") def _get_player_markers(self): self.player_markers[PLAYER_1] = input(f"{self.player_names[PLAYER_1]}, choose your marker (X/O):\n> ").upper() while self.player_markers[PLAYER_1] not in ["X", "O"]: print('>>> Invalid marker! Please choose either "X" or "O".') self.player_markers[PLAYER_1] = input(f"{self.player_names[PLAYER_1]}, choose your marker (X/O):\n> ").upper() self.player_markers[PLAYER_2] = "X" if self.player_markers[PLAYER_1] == "O" else "O" def _switch_current_player(self): if self.current_player == PLAYER_1: self.current_player = PLAYER_2 else: self.current_player = PLAYER_1 def _location_is_taken(self, board_index): return self.current_board[board_index] in self.player_markers.values() def _check_if_board_is_full(self): return True if all(marker in self.player_markers.values() for marker in self.current_board) else False def _player_has_won(self, player): for win_combo in self.WIN_COMBOS: if set(win_combo) <= set(self._get_player_locations(player)): return True return False # if no winning combinations were found def _get_player_locations(self, player): return [index for index, marker in enumerate(self.current_board) if marker == self.player_markers[player]] @staticmethod def _get_next_move(): while True: chosen_location = input("Cross location (choose 1 - 9):\n> ") if not chosen_location.isdigit() or int(chosen_location) not in range(1, 10): print('>>> Invalid input!') continue else: chosen_location = int(chosen_location) - 1 # adjust for array index to start at 0 not 1 return chosen_location if __name__ == '__main__': NoughtsAndCrosses().play()
- PLAYER_1 = 1
- PLAYER_2 = 2
- class NoughtsAndCrosses(object):
- """Basic implementation of Noughts and Crosses"""
- WIN_COMBOS = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
- EMPTY_BOARD = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
- def __init__(self):
- self.current_board = self.EMPTY_BOARD.copy()
- self.current_player = PLAYER_1 # game always starts with PLAYER_1
- self.player_names = {}
self.location_lists = {PLAYER_1: [],PLAYER_2: []}- self.player_markers = {
PLAYER_1: "X",PLAYER_2: "O",- PLAYER_1: "",
- PLAYER_2: "",
- }
- def _print_board(self):
- """Prints the current board"""
- print("--- Noughts and Crosses ---")
- print(f'{self.current_board[0]} : {self.current_board[1]} : {self.current_board[2]}')
- print("..........")
- print(f'{self.current_board[3]} : {self.current_board[4]} : {self.current_board[5]}')
- print("..........")
- print(f'{self.current_board[6]} : {self.current_board[7]} : {self.current_board[8]}')
- def play(self):
- self._print_welcome_message()
- self._get_player_names()
- self._get_player_markers()
- while True:
- self._let_current_player_move()
- if self._player_has_won(self.current_player):
- print(f"{self.player_names[self.current_player]}, you have won!")
- break
- elif self._check_if_board_is_full():
- print(f"Stalemate - End of game")
- break
- self._switch_current_player()
- def _let_current_player_move(self):
- print("Hi", self.player_names[self.current_player])
- while True:
- chosen_board_index = self._get_next_move()
- if self._location_is_taken(chosen_board_index):
- print('>>> Position taken, try again!')
- continue
- else:
self._update_board_and_location_lists(chosen_board_index)- self._update_board(chosen_board_index)
- self._print_board()
- break
def _update_board_and_location_lists(self, chosen_board_index):- def _update_board(self, chosen_board_index):
- self.current_board[chosen_board_index] = self.player_markers[self.current_player]
self.location_lists[self.current_player].append(chosen_board_index)- @staticmethod
- def _print_welcome_message():
- print("*" * 50)
- print("Welcome to our Noughts and Crosses Game!")
- print("*" * 50)
- def _get_player_names(self):
- self.player_names[1] = input("Enter the name of the first player:\n> ")
- self.player_names[2] = input("Enter the name of the second player:\n> ")
- def _get_player_markers(self):
- self.player_markers[PLAYER_1] = input(f"{self.player_names[PLAYER_1]}, choose your marker (X/O):\n> ").upper()
- while self.player_markers[PLAYER_1] not in ["X", "O"]:
- print('>>> Invalid marker! Please choose either "X" or "O".')
- self.player_markers[PLAYER_1] = input(f"{self.player_names[PLAYER_1]}, choose your marker (X/O):\n> ").upper()
- self.player_markers[PLAYER_2] = "X" if self.player_markers[PLAYER_1] == "O" else "O"
- def _switch_current_player(self):
- if self.current_player == PLAYER_1:
- self.current_player = PLAYER_2
- else:
- self.current_player = PLAYER_1
- def _location_is_taken(self, board_index):
- return self.current_board[board_index] in self.player_markers.values()
- def _check_if_board_is_full(self):
return True if len(self.location_lists[PLAYER_1] + self.location_lists[PLAYER_2]) == 9 else False- return True if all(marker in self.player_markers.values() for marker in self.current_board) else False
- def _player_has_won(self, player):
- for win_combo in self.WIN_COMBOS:
if set(win_combo) <= set(self.location_lists[player]):- if set(win_combo) <= set(self._get_player_locations(player)):
- return True
return False # if no winning combinations was found- return False # if no winning combinations were found
- def _get_player_locations(self, player):
- return [index for index, marker in enumerate(self.current_board) if marker == self.player_markers[player]]
- @staticmethod
- def _get_next_move():
- while True:
chosen_location = input("Cross location(choose 1 - 9):> ")if not chosen_location.isdigit() or int(chosen_location) not in range(10):- chosen_location = input("Cross location (choose 1 - 9):
- > ")
- if not chosen_location.isdigit() or int(chosen_location) not in range(1, 10):
- print('>>> Invalid input!')
- continue
- else:
- chosen_location = int(chosen_location) - 1 # adjust for array index to start at 0 not 1
- return chosen_location
- if __name__ == '__main__':
- NoughtsAndCrosses().play()
module Solution where make_mod_repr d repr n | n `mod` d == 0 = Just repr | otherwise = Nothing mod_3_repr = make_mod_repr 3 "fizz" mod_5_repr = make_mod_repr 5 "buzz" fizzbuzz :: [String] -> Int -> Int -> [String] fizzbuzz _ i n = map fizzbuzz' [i .. n] where fizzbuzz' x | repr == Nothing = show x | otherwise = (\(Just x) -> x) repr where repr = foldl (\acc f -> acc <> f x) Nothing [mod_3_repr, mod_5_repr] -- we don't need the empty accumulator -- could be fizzbuzz :: Int -> Int -> [String]
- module Solution where
- make_mod_repr d repr n | n `mod` d == 0 = Just repr
- | otherwise = Nothing
- mod_3_repr = make_mod_repr 3 "fizz"
- mod_5_repr = make_mod_repr 5 "buzz"
- fizzbuzz :: [String] -> Int -> Int -> [String]
- fizzbuzz _ i n = map fizzbuzz' [i .. n]
where fizzbuzz' n| n `mod` 15 == 0 = "fizzbuzz"| n `mod` 3 == 0 = "fizz"| n `mod` 5 == 0 = "buzz"| otherwise = show n- where
- fizzbuzz' x | repr == Nothing = show x
- | otherwise = (\(Just x) -> x) repr
- where
- repr = foldl (\acc f -> acc <> f x) Nothing [mod_3_repr, mod_5_repr]
- -- we don't need the empty accumulator
- -- could be fizzbuzz :: Int -> Int -> [String]
import codewars_test as test from solution import OrdinalNumbers @test.describe("Example") def test_group(): @test.it("test case 1: (1-10)") def test_case(): samples = [n for n in range(1, 11)] expected = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th'] for s, e in zip(samples, expected): test.assert_equals(OrdinalNumbers(s).solution(), e) @test.it("test case 2: (11-30)") def test_case(): samples = [n for n in range(11, 31)] expected = ['11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th', '29th', '30th'] for s, e in zip(samples, expected): test.assert_equals(OrdinalNumbers(s).solution(), e) @test.it("test case 3: Random") def test_case(): samples = [776, 411, 1001100, 99999999, 567090803542432, 33197390315682527] expected = ['776th', '411th', '1001100th', '99999999th', '567090803542432nd', '33197390315682527th'] for s, e in zip(samples, expected): test.assert_equals(OrdinalNumbers(s).solution(), e)
- import codewars_test as test
- from solution import OrdinalNumbers
- @test.describe("Example")
- def test_group():
- @test.it("test case 1: (1-10)")
- def test_case():
- samples = [n for n in range(1, 11)]
- expected = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th']
- for s, e in zip(samples, expected):
- test.assert_equals(OrdinalNumbers(s).solution(), e)
- @test.it("test case 2: (11-30)")
- def test_case():
- samples = [n for n in range(11, 31)]
- expected = ['11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th', '29th', '30th']
- for s, e in zip(samples, expected):
- test.assert_equals(OrdinalNumbers(s).solution(), e)
- @test.it("test case 3: Random")
- def test_case():
- samples = [776, 411, 1001100, 99999999, 567090803542432, 33197390315682527]
expected = ['776th', '411st', '1001100th', '99999999th', '567090803542432nd', '33197390315682527th']- expected = ['776th', '411th', '1001100th', '99999999th', '567090803542432nd', '33197390315682527th']
- for s, e in zip(samples, expected):
- test.assert_equals(OrdinalNumbers(s).solution(), e)
function* blaze_it() { yield 69; yield 420; yield 1337; }; const dark_tech = blaze_it() let a=10; a = dark_tech.next().value; a = dark_tech.next().value; a = dark_tech.next().value; const b = 42; a = 10*b; a= 17; a - Math.sin(Math.PI / 2); a = a^69; a=420;
- function* blaze_it() {
- yield 69;
- yield 420;
- yield 1337;
- };
- const dark_tech = blaze_it()
- let a=10;
- a = dark_tech.next().value;
- a = dark_tech.next().value;
- a = dark_tech.next().value;
- const b = 42;
- a = 10*b;
a= 12;- a= 17;
- a - Math.sin(Math.PI / 2);
- a = a^69;
a=10- a=420;
#include<bits/stdc++.h> using namespace std; long add_arr(vector<int> arr) { return std::accumulate(begin(arr),end(arr),0); }
#include <vector>#include <numeric>- #include<bits/stdc++.h>
- using namespace std;
longadd_arr(std::vector<int> arr)- long add_arr(vector<int> arr)
- {
return std::accumulate(arr.begin(),arr.end(),0);- return std::accumulate(begin(arr),end(arr),0);
- }