Moved the parts of network out of server.
Partly added extensions to tic-tac-toe py.
This commit is contained in:
parent
f59d59814a
commit
71fa6f30ba
10 changed files with 237 additions and 74 deletions
15
games/tic-tac-toe/data.py
Normal file
15
games/tic-tac-toe/data.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
def greatest_sequence(match, pattern):
|
||||
m = match
|
||||
p = pattern
|
||||
size = 0
|
||||
max_size = 0
|
||||
|
||||
for p in pattern:
|
||||
if m == p:
|
||||
size += 1
|
||||
else:
|
||||
if size > max_size:
|
||||
max_size = size
|
||||
size = 0
|
||||
|
||||
return max_size
|
BIN
games/tic-tac-toe/data.pyc
Normal file
BIN
games/tic-tac-toe/data.pyc
Normal file
Binary file not shown.
15
games/tic-tac-toe/player.py
Normal file
15
games/tic-tac-toe/player.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from pygame.mouse import get_pos
|
||||
from point import Point
|
||||
|
||||
class Player(object):
|
||||
def __init__(self, id, shape, board):
|
||||
self.shape = shape
|
||||
self.board = board
|
||||
self.id = id
|
||||
|
||||
|
||||
def turn(self):
|
||||
#Ask mouse for position
|
||||
board.make_turn(Point(get_pos()[0],get_pos()[1]))
|
||||
|
||||
|
23
games/tic-tac-toe/server.py
Normal file
23
games/tic-tac-toe/server.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
#server.py
|
||||
import json
|
||||
from socket import socket, AF_INET, SOCK_STREAM
|
||||
|
||||
|
||||
class server(object):
|
||||
def __init__(self, port=None):
|
||||
self.port = port
|
||||
self.world = GGS.init()
|
||||
self.socket = socket(AF_INET, SOCK_STREAM)
|
||||
self.socket.connect(("www.???.com", 80))
|
||||
|
||||
def turn(self, id, index):
|
||||
rows = sqrt(board.nr_of_rectangles)
|
||||
x = int(index / rows)
|
||||
y = int(index % rows)
|
||||
|
||||
json.dumps({"x": x, "y": y}
|
||||
world.callCommand("tictactoe", "set", json.dumps({"x": x, "y": y}))
|
||||
|
||||
sent = 0
|
||||
length = len(
|
||||
while sent
|
14
games/tic-tac-toe/test_data.py
Normal file
14
games/tic-tac-toe/test_data.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import unittest
|
||||
import data
|
||||
|
||||
|
||||
class TestData(unittest.TestCase):
|
||||
def setUp(self):
|
||||
array = [0,1,1,1,3,4,5,2,2,3,3,3,3,3,33,4,2,2]
|
||||
|
||||
self.assertTrue(data.greatest_sequence(array, 3) == 5)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
Reference in a new issue