I'm trying to make a chopsticks game. Here's a wikipedia link to the game https://en.wikipedia.org/wiki/Chopsticks_(hand_game). So far I just added a couple methods so that one hand can attack another hand using the 'attack' method. I feel like the code I wrote is very verbose, ugly and maybe even wrong though. How can I write this more elegantly?
class game:
def __init__(self):
self.x_left = 1
self.x_right = 1
self.o_left = 1
self.o_right = 1
def set_x_left(self, num):
self.x_left = num
def set_x_right(self, num):
self.x_right = num
def set_o_left(self, num):
self.o_left = num
def set_o_right(self, num):
self.o_right = num
def dict_func(self, hand):
self.func= {'x_left': self.set_x_left, 'x_right': self.set_x_right,
'o_left': self.set_o_left, 'o_right': self.set_o_right}
return self.func[hand]
def dict_hand(self, hand):
self.hands = {'x_left': self.x_left, 'x_right': self.x_right,
'o_left': self.o_left, 'o_right': self.o_right}
return self.hands[hand]
def attack(self, from_hand, to_hand):
self.dict_func(to_hand)(self.dict_hand(from_hand) + self.dict_hand(to_hand))