g3x0

Xn0

Jan 16th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. def check(opt, choice):
  2.     if opt[0][0] == choice and opt[0][1] == choice and opt[0][2] == choice:
  3.         return 1;
  4.     if opt[1][0] == choice and opt[1][1] == choice and opt[1][2] == choice:
  5.         return 1;
  6.     if opt[2][0] == choice and opt[2][1] == choice and opt[2][2] == choice:
  7.         return 1;
  8.     if opt[0][0] == choice and opt[1][1] == choice and opt[2][2] == choice:
  9.         return 1;
  10.     if opt[0][2] == choice and opt[1][1] == choice and opt[2][0] == choice:
  11.         return 1;
  12.     if opt[0][0] == choice and opt[1][0] == choice and opt[2][0] == choice:
  13.         return 1;
  14.     if opt[0][1] == choice and opt[1][1] == choice and opt[2][1] == choice:
  15.         return 1;
  16.     if opt[0][2] == choice and opt[1][2] == choice and opt[2][2] == choice:
  17.         return 1;
  18.  
  19. p = 2
  20. xo = [['+','+','+'],['+','+','+'],['+','+','+']]
  21. wins = [0,0]
  22. play = 'y'
  23. while play == 'y':
  24.     p = p+1
  25.     if p % 2 == 1:
  26.         player = 1
  27.         ch = 'X'
  28.     else:
  29.         player = 2
  30.         ch = 'O'
  31.     print 'Player 1:', wins[0], '| Player 2:', wins[1]
  32.     for i in xo:
  33.         print '\t', i[0], i[1], i[2]
  34.     print 'Player:', player, '[' + ch + ']:'
  35.     c = input('>>> ')
  36.     f = c/10 - 1;
  37.     l = c%10 - 1;
  38.     while xo[f][l] != '+':
  39.          c = input('>>> ')
  40.     xo[f][l] = ch
  41.     if check(xo, ch):
  42.         wins[player-1] = wins[player-1] + 1
  43.         xo = [['+','+','+'],['+','+','+'],['+','+','+']]
  44.         play = raw_input('Play again?[y/n]: ')
Advertisement
Add Comment
Please, Sign In to add comment