Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adding win_by vertical and win_horizontal ... #4

Merged
merged 1 commit into from

2 participants

sudevs Kevin Clark
sudevs

that we did after coming back from dojo event. May interest others.

Kevin Clark kevinclark merged commit 04af37b into from
Kevin Clark
Owner

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 17, 2012
  1. sudevs

    Adding win_by vertical and win_horizontal that we did after coming ba…

    sudevs authored
    …ck from dojo event. May interest others.
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 1 deletion.
  1. +7 −1 tictactoe.py
8 tictactoe.py
View
@@ -7,9 +7,15 @@ def print_board():
def win_by_diagonal(mark):
return (board[0] == mark and board[4] == mark and board[8] == mark) or (board[6] == mark and board[4] == mark and board[2] == mark)
+
+def win_by_vertical(mark):
+ return (board[0] == mark and board[3] == mark and board[6] == mark) or (board[1] == mark and board[4] == mark and board[7] == mark) or (board[2] == mark and board[5] == mark and board[8]== mark)
+
+def win_by_horizontal(mark):
+ return (board[0] == mark and board[1] == mark and board[2] == mark) or (board[3] == mark and board[4] == mark and board[5] == mark) or (board[6] == mark and board[7] == mark and board[8] == mark)
def make_mark(mark, space):
board[space] = mark
print_board()
- if win_by_diagonal(mark):
+ if win_by_diagonal(mark) or win_by_vertical(mark) or win_by_horizontal(mark):
print mark + ' Wins!'
Something went wrong with that request. Please try again.