-
Notifications
You must be signed in to change notification settings - Fork 1
/
connect4-0.7.py
73 lines (60 loc) · 2.68 KB
/
connect4-0.7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# WORK IN PROGRESS
# HAS SOME BUGS:
"""
#1: Doesn't show what pieces are in each column until it fills.
#2: Only swaps pieces when using different columns. Pieces in column one for example will all be X or all O, and same for the other columns.
...and probably others that I haven't found.
"""
# Import os and platform.
import os, platform
# Check what operating system the program is running on.
if platform.system() == "Windows":
def clear():
os.system('cls')
else:
def clear():
os.system('clear')
# Define the variable that holds the board places.
board = [
["_", "_", "_", "_", "_", "_", "_"],
["_", "_", "_", "_", "_", "_", "_"],
["_", "_", "_", "_", "_", "_", "_"],
["_", "_", "_", "_", "_", "_", "_"],
["_", "_", "_", "_", "_", "_", "_"],
["_", "_", "_", "_", "_", "_", "_"],
]
colIndxs = [5, 5, 5, 5, 5, 5, 5]
moveIsInt = 1
moveIs = "X"
isFull = [" ", " ", " ", " ", " ", " ", " "]
# Define the function to print the board.
def printBoard():
clear()
print("|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" % (board[0][0], board[0][1], board[0][2], board[0][3], board[0][4], board[0][5], board[0][6]))
print("|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" % (board[0][0], board[0][1], board[0][2], board[0][3], board[0][4], board[0][5], board[0][6]))
print("|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" % (board[0][0], board[0][1], board[0][2], board[0][3], board[0][4], board[0][5], board[0][6]))
print("|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" % (board[0][0], board[0][1], board[0][2], board[0][3], board[0][4], board[0][5], board[0][6]))
print("|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" % (board[0][0], board[0][1], board[0][2], board[0][3], board[0][4], board[0][5], board[0][6]))
print("|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" % (board[0][0], board[0][1], board[0][2], board[0][3], board[0][4], board[0][5], board[0][6]))
print(" %s %s %s %s %s %s %s" % (isFull[0], isFull[1], isFull[2], isFull[3], isFull[4], isFull[5], isFull[6]))
stillPlaying = "y"
while stillPlaying == "y":
if (moveIsInt%2) == 0:
moveIs = "O"
elif (moveIsInt%2) != 0:
moveIs = "X"
# Ask for move.
move = ""
printBoard()
move = input(f"{moveIs}'s Turn | Column to place your piece (number 1-7): ")
if move == "" or int(move) > 7 or int(move) < 1 or board[colIndxs[int(move)-1]][int(move)-1] != "_":
print("Invalid Move.")
else:
board[colIndxs[int(move)-1]][int(move)-1] = moveIs
colIndxs[int(move)-1] -= 1
moveIsInt += 1
printBoard()
if colIndxs[int(move)-1] < 0:
isFull[int(move)-1] = "F"
printBoard()
print("That column is full!")