Skip to content
Snippets Groups Projects
Commit a6668582 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
Branches
Tags
No related merge requests found
.idea
main.py 0 → 100644
from kivy.app import App
from kivy.properties import BooleanProperty, ListProperty
from functools import reduce
from operator import xor
__app_package__ = 'edu.unl.cse.soft161.nim'
__app__ = 'Nim'
__version__ = '0.1'
__flags__ = ['--bootstrap=sdl2', '--requirements=python2,kivy', '--orientation=landscape']
class NimApp(App):
heaps = ListProperty([3, 5, 7])
take_enabled = ListProperty([True, True, True])
next_enabled = BooleanProperty(True)
def make_computer_move(self):
nimber = reduce(xor, self.heaps, 0)
for index, heap in enumerate(self.heaps):
if nimber ^ heap < heap:
self.heaps[index] = nimber ^ heap
break
else:
self.heaps[self.heaps.index(max(self.heaps))] -= 1
def reset(self):
self.heaps = [3, 5, 7]
def take(self, index):
pass
def next(self):
pass
if __name__ == '__main__':
nim = NimApp()
nim.run()
nim.kv 0 → 100644
BoxLayout:
orientation: 'vertical'
BoxLayout:
orientation: 'horizontal'
BoxLayout:
orientation: 'vertical'
Label:
size_hint: (1, 0.25)
text: 'Heap A:'
Label:
font_size: '150sp'
text: str(app.heaps[0])
Button:
size_hint: (1, 0.25)
disabled: not app.take_enabled[0]
text: 'Take A'
on_press: app.take(0)
BoxLayout:
orientation: 'vertical'
Label:
size_hint: (1, 0.25)
text: 'Heap B:'
Label:
font_size: '150sp'
text: str(app.heaps[1])
Button:
size_hint: (1, 0.25)
disabled: not app.take_enabled[1]
text: 'Take B'
on_press: app.take(1)
BoxLayout:
orientation: 'vertical'
Label:
size_hint: (1, 0.25)
text: 'Heap C:'
Label:
font_size: '150sp'
text: str(app.heaps[2])
Button:
size_hint: (1, 0.25)
disabled: not app.take_enabled[2]
text: 'Take C'
on_press: app.take(2)
BoxLayout:
size_hint: (1, 0.2)
orientation: 'horizontal'
Button:
text: 'New Game'
on_press: app.reset()
Button:
disabled: not app.next_enabled
text: 'Next'
on_press: app.next()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment