creating a minesweeper game in pygame and i am getting a recursion error when running my code. how do i mitigate this? This is the code I have that checks to see if the clicked grid square is empty and if it is then it reveals that grid square as well as all the adjacent squares. the section that is getting this error is below:
def reveal_empty(rn,c, grid, revealed,box):
if grid[rn][c] != '0' and grid[rn][c] != '*':
revealed[rn][c] = True
if grid[rn][c] == '0':
revealed[rn][c] = True
# change row above
if rn-1 > -1:
r = grid[rn-1]
if c-1 > -1:
if not r[c-1] == '*':
revealed[rn-1][c-1] = True
reveal_empty(rn-1,c-1, grid, revealed,box)
if not r[c] == '*':
revealed[rn-1][c] = True
reveal_empty(rn-1,c, grid, revealed,box)
if c+1 < 10:
if not r[c+1] == '*':
revealed[rn-1][c+1] = True
reveal_empty(rn-1,c+1, grid, revealed,box)
#change same row
r = grid[rn]
if c-1 > -1:
if not r[c-1] == '*':
revealed[rn][c-1] + True
reveal_empty(rn,c-1, grid, revealed,box)
if c+1 < 10:
if not r[c+1] == '*':
revealed[rn][c+1] = True
reveal_empty(rn,c+1, grid, revealed,box)
#change row below
if rn+1 < 11:
r = grid[rn + 1]
if c-1 > -1:
if not r[c-1] == '*':
revealed[rn+1][c-1] = True
reveal_empty(rn+1,c-1, grid, revealed,box)
if not r[c] == '*':
revealed[rn+1][c] = True
reveal_empty(rn+1,c, grid, revealed,box)
if c+1 < 11:
if not r[c+1] == '*':
revealed[rn+1][c+1] = True
reveal_empty(rn+1,c+1, grid, revealed,box)
I guess you have this problem because there is no quick exit-clause for your recursive function. I suspect that because you don't check to see if the cell is already revealed ( revealed[row][col] == True ), then it never exits - it keeps recursing for ones already half-done in the processing queue (stack).
Maybe a quick check at the beginning of the function will fix it:
def reveal_empty( row, col, grid, revealed, box ):
if ( revealed[row][col] == False ):
# do recursive check else here!
else:
print("Cell[%d][%d] is already revealed" % ( row, col ) )
I figured it out. I had to add a check to each step of the recursion to check if the value has been revealed yet. see below:
# change row above
if rn-1 > -1:
r = grid[rn-1]
if c-1 >= -1:
if not r[c-1] == '*' and revealed[rn-1][c-1] == False:
revealed[rn-1][c-1] = True
if grid[rn-1][c-1] == '0':
reveal_empty(rn-1,c-1, grid, revealed,box)
if not r[c] == '*' and revealed[rn-1][c] == False:
revealed[rn-1][c] = True
if grid[rn-1][c] == '0':
reveal_empty(rn-1,c, grid, revealed,box)
if c+1 < 10:
if not r[c+1] == '*' and revealed[rn-1][c+1] == False:
revealed[rn-1][c+1] = True
if grid[rn-1][c+1] == '0':
reveal_empty(rn-1,c+1, grid, revealed,box)
#change same row
r = grid[rn]
if c-1 > -1:
if not r[c-1] == '*' and revealed[rn][c-1] == False:
revealed[rn][c-1] + True
if grid[rn][c-1] == '0':
reveal_empty(rn,c-1, grid, revealed,box)
if c+1 < 10:
if not r[c+1] == '*' and revealed[rn][c+1] == False:
revealed[rn][c+1] = True
if grid[rn][c+1] == '0':
reveal_empty(rn,c+1, grid, revealed,box)
#change row below
if rn+1 < 11:
r = grid[rn + 1]
if c-1 > -1:
if not r[c-1] == '*' and revealed[rn+1][c-1] == False:
revealed[rn+1][c-1] = True
if grid[rn+1][c-1] == '0':
reveal_empty(rn+1,c-1, grid, revealed,box)
if not r[c] == '*' and revealed[rn+1][c] == False:
revealed[rn+1][c] = True
if grid[rn+1][c] == '0':
reveal_empty(rn+1,c, grid, revealed,box)
if c+1 < 11:
if not r[c+1] == '*' and revealed[rn+1][c+1] == False:
revealed[rn+1][c+1] = True
if grid[rn+1][c+1] == '0':
reveal_empty(rn+1,c+1, grid, revealed,box)
Related
I'm trying for a while now to submit my solution to the following problem on Kattis: I can guess the data structure!. However, I keep getting a runtime error; I cannot think of anywhere it can go wrong since it works with all my input. Here is my solution:
import heapq, sys
def throwin(q,s,h,x, results):
if results[0]:
q.append(x)
if results[1]:
s.append(x)
if results[2]:
heapq.heappush(h, -x)
return (q,s ,h )
def printstructures(l):
for j in l:
if j[0] and j[1] or j[0] and j[2] or j[1] and j[2]:
print("not sure")
elif not j[0] and not j[1] and not j[2]:
print("impossible")
elif j[0]:
print("queue")
elif j[1]:
print("stack")
else:
print("priority queue")
def main():
results_global = []
stackops = []
current = []
while True:
try:
line = input()
if len(line) == 1:
if len(current) != 0:
stackops.append(current)
current = []
else:
current.append(tuple(map(int, line.split(" "))))
except EOFError:
break
stackops.append(current)
for op in stackops:
q,s,h = [],[],[]
heapq._heapify_max(h)
results = [True, True, True]
for i in range(len(op)):
o, x = op[i]
if o == 1:
q,s,h = throwin(q,s,h,x, results)
else:
if len(q) == 0 or q[0] != x:
results[0] = False
else:
q.pop(0)
if len(s) == 0 or s[-1] != x:
results[1] = False
else:
s.pop()
if len(h) == 0 or h[0] != -x :
results[2] = False
else:
heapq.heappop(h)
if i == len(op)-1:
results_global.append(results)
printstructures(results_global)
if __name__ == "__main__":
main()
I was wondering if anyone can give me a push in the right direction and point out where my thinking is wrong or if I made a mistake somewhere I overlooked.
I had the same runtime-error problem for this question, I think it has something to do with python input/output EOFError. I couldn't figure the specific error out but I just put a try/except pass over my entire program and kattis accepted the solution.
import sys
try:
def solve(n):
stack = []
queue = []
priority_queue = []
type_ds = [True, True, True]
for i in range(n):
command, element = map(int, input().split())
if command == 1:
if type_ds[0] != False:
stack.append(element)
if type_ds[1] != False:
queue.append(element)
if type_ds[2] != False:
priority_queue.append(element)
elif command == 2:
if type_ds[0] != False:
if len(stack) == 0:
return "impossible"
if element != stack.pop():
type_ds[0] = False
stack.clear()
if type_ds[1] != False:
if len(queue) == 0:
return "impossible"
if element != queue.pop(0):
type_ds[1] = False
queue.clear()
if type_ds[2] != False:
if len(priority_queue) == 0:
return "impossible"
priority_queue.sort(reverse=True)
if element != priority_queue.pop(0):
type_ds[2] = False
priority_queue.clear()
if type_ds.count(True) > 1:
return "not sure"
elif type_ds.count(True) == 0:
return "impossible"
else:
if type_ds[0] == True:
return "stack"
elif type_ds[1] == True:
return "queue"
else:
return "priority queue"
for line in sys.stdin:
if line.strip() == "":
break
n = int(line.strip())
print(solve(n))
except:
pass
Are you sure you're breaking out of the while loop? Is it running correctly on your computer? In competitive programming, with time limits, it's normally not a good idea to use try/except statements, it's slowing down the script by a lot.
I'm building out Battleships game in Python. I have a list and I'm trying to build a validation tool in Python to catch user inputs that are outside the 10x10 range of my list.
Here is the code:
from random import randint
player = "User"
board = []
board_size = 10
ships = {"Aircraft Carrier":5,
"Battleship":4,
"Submarine":3,
"Destroyer":3,
"Patrol Boat":2}
def print_board(player, board): # to print joined board
print("Here is " + player + "'s board")
for row in board:
print(" ".join(row))
def switch_user(player): # to switch users
if player == "User":
player = "Computer"
elif player == "Computer":
player = "User"
else:
print("Error with user switching")
for x in range(0, board_size): # to create a board
board.append(["O"] * board_size)
print_board(player,board)
def random_row(board): # generate random row
return randint(0, len(board) - 1)
def random_col(board): # generate random column
return randint(0, len(board[0]) - 1)
def user_places_ships(board, ships): # user choses to place its ships by providing starting co-ordinate and direction.
for ship in ships:
valid = False
while(not valid):
user_input_coordinates = input("Please enter row & column number for your " + str(ship) + ", which is " + str(ships[ship]) + "-cells long (row, column).")
ship_row, ship_col = user_input_coordinates.split(",")
ship_row = int(ship_row)
ship_col = int(ship_col)
user_input_dir = input("Please enter direction for your " + str(ship) + ", which is " + str(ships[ship]) + "-cells long (h for horizontal or v for vertical).")
valid = validate_coordinates(board, ships[ship], ship_row, ship_col, user_input_dir)
if not valid:
print("The ship coordinates either outside of" , board_size, "X" , board_size, "range, overlap with or too close to another ship.")
place_ship(board, ships[ship], ship_row, ship_col, user_input_dir)
print("You have finished placing all your ships.")
def validate_coordinates(board, ship_len, row, col, dir): # validates if the co-ordinates entered by a player are within the board and don't overlap with other ships
if dir == "h" or dir == "H":
for x in range(ship_len):
if row-1 > board_size or col-1+x > board_size:
return False
elif row-1 < 0 or col-1+x < 0:
return False
elif board[row-1][col-1+x] == "S":
return False
elif dir == "v" or dir == "V":
for x in range(ship_len):
if row-1+x > board_size or col-1 > board_size:
return False
elif row-1+x < 0 or col-1 < 0:
return False
elif board[row-1+x][col-1] == "S":
return False
return True
def place_ship(board, ship_len, row, col, dir): # to actually place ships and mark them as "S"
if dir == "h" or dir == "H":
for x in range(ship_len):
board[row-1][col-1+x] = "S"
elif dir == "v" or dir == "V":
for x in range(ship_len):
board[row-1+x][col-1] = "S"
else:
print("Error with direction.")
print_board(player,board)
user_places_ships(board,ships)
If a user enters "10,10" for ship coordinates and "h" for horizontal direction, then Python generates the following error message:
Traceback (most recent call last): File "C:/Users/Elchin's PC/Downloads/battleships game.py", line 85, in <module>
user_places_ships(board,ships) File "C:/Users/Elchin's PC/Downloads/battleships game.py", line 49, in user_places_ships
valid = validate_coordinates(board, ships[ship], ship_row, ship_col, user_input_dir) File "C:/Users/Elchin's PC/Downloads/battleships game.py", line 62, in validate_coordinates
elif board[row-1][col-1+x] == "S": IndexError: list index out of range
I know that the error is in this line:
elif board[row-1][col-1+x] == "S":
return False
But I don't know how to fix it. Could you please help me figure out the solution?
If a list has length n, you can access indices from 0 to n-1 (both inclusive).
Your if statements however check:
if row-1+x > board_size or col-1 > board_size: # greater than n
return False
elif row-1+x < 0 or col-1 < 0: # less than 0
return False
elif board[row-1+x][col-1] == "S":
return False
So as a result, if we reach the last elif part, we have guarantees that the indices are 0 < i <= n. But these should be 0 < i < n.
So you should change the first if statement to:
if row-1+x >= board_size or col-1 >= board_size: # greater than or equal n
return False
elif row-1+x < 0 or col-1 < 0: # less than 0
return False
elif board[row-1+x][col-1] == "S":
return False
You can make the code more elegant by writing:
if not (0 < row-1+x < board_size and 0 < col-1 < board_size) or \
board[row-1+x][col-1] == "S":
return False
I am trying to convert the code here http://www.geeksforgeeks.org/expression-evaluation/ to python. However, I am running into some trouble and can't figure out.
class evaluateString:
def evalString(self,expression):
valueStack = []
opStack = []
i=0
while(i<len(expression)):
if(expression[i] == ' '):
continue
if(expression[i]>='0' and expression[i] <= '9'):
charNumber = [] #for storing number
while(i<len(expression) and expression[i]>='0' and expression[i] <= '9'):
charNumber.append(expression[i])
i+=1
valueStack.append(int(''.join(charNumber)))
elif (expression[i]=='('):
opStack.append(expression[i])
elif (expression[i]==')'):
while(opStack[-1]!='('):
valueStack.append(self.applyOperation(opStack.pop(),valueStack.pop(),valueStack.pop()))
opStack.pop()
elif(expression[i]=='+'or expression[i]=='-'or expression[i]=='*'or expression[i]=='/'):
while( (len(opStack)!=0) and ( self.opPrecedence(expression[i],opStack[-1]) ) ):
valueStack.append(self.applyOperation(opStack.pop(),valueStack.pop(),valueStack.pop()))
opStack.append(expression[i])
i = i + 1
while(len(opStack)!=0):
valueStack.append(self.applyOperation(opStack.pop(),valueStack.pop(),valueStack.pop()))
return valueStack.pop()
def applyOperation(self,op,a,b):
if op=='+':
return a+b
elif op=='-':
return a-b
elif op=='*':
return a*b
elif op=='/':
return a/b
else:
return 0
def opPrecedence(self,op1,op2):
if (op2 == '(' or op2 == ')'):
return False
if ((op1 == '*' or op1 == '/') and (op2 == '+' or op2 == '-')):
return False
else:
return True
a = evaluateString()
print(a.evalString("(5+7)"))
I am able to get the right numbers in the valueStack. However, there seems to be problem in the last two elseif. Can someone point me in the right direction?
I have done some fixes and it works for some operations. But I haven't tested it for all cases. Also, operations are only integers, no floats (e.g. check last output below).
class evaluateString:
def evalString(self,expression):
valueStack = []
opStack = []
i=0
while(i<len(expression)):
if(expression[i] == ' '):
continue
if(expression[i]>='0' and expression[i] <= '9'):
charNumber = [] #for storing number
j = i
while(j<len(expression) and expression[j]>='0' and expression[j] <= '9'):
charNumber.append(expression[j])
j += 1
i = (j-1)
valueStack.append(int(''.join(charNumber)))
elif (expression[i]=='('):
opStack.append(expression[i])
elif (expression[i]==')'):
while(opStack[-1]!='('):
valueStack.append(self.applyOperation(opStack.pop(),valueStack.pop(),valueStack.pop()))
opStack.pop()
elif(expression[i]=='+'or expression[i]=='-'or expression[i]=='*'or expression[i]=='/'):
while( (len(opStack)!=0) and ( self.opPrecedence(expression[i],opStack[-1]) ) ):
valueStack.append(self.applyOperation(opStack.pop(),valueStack.pop(),valueStack.pop()))
opStack.append(expression[i])
i = i + 1
while(len(opStack)!=0):
valueStack.append(self.applyOperation(opStack.pop(),valueStack.pop(),valueStack.pop()))
return valueStack.pop()
def applyOperation(self,op,a,b):
if op=='+':
return a+b
elif op=='-':
return b-a
elif op=='*':
return a*b
elif op=='/':
return b/a
else:
return 0
def opPrecedence(self,op1,op2):
if (op2 == '(' or op2 == ')'):
return False
if ((op1 == '*' or op1 == '/') and (op2 == '+' or op2 == '-')):
return False
else:
return True
a = evaluateString()
print(a.evalString("8*12")) #prints 96
print(a.evalString("(122-434)")) #prints -312
print(a.evalString("(232+12)/2")) #print 122
print(a.evalString("232/12+2")) #prints 21
In python eval() will evaluate infix expressions
print(eval("(5+7)/2"))
it will print the evaluated infix expression value as 6.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm very new to Python and I have to create a tic tac toe game with 3 players, 'X', 'O' and 'Y'. The grid has to be 6x6 instead of the normal 3x3. I have been having a lot of trouble with this and I'm very unsure how to do it. I have a 2 player 3x3 game working but implementing another player and validating the wins is becoming more tedious than I previously expected. I need help with validating a win. I haven't written the code to check for a diagonal win because I want to get everything else working before I do that. This is what I have so far but it's not correct. It's not printing out the values entered and when I do enter a value it says X has won straight away. I'd really appreciate it if you could help me. Thanks!
grid = [[0,0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0,0]]
def get_state(grid, row, col):
occupant = grid[col-1][row-1]
if occupant == 1:
return 'X'
if occupant == 2:
return 'O'
if occupant == 3:
return 'Y'
return ' '
def set_state(grid, row, col, player):
if player == 'X':
occupant = 1
elif player == 'O':
occupant = 2
elif player == 'Y':
occupant = 3
grid[col-1][row-1] = occupant
def is_winner(grid):
if grid[0][0] == grid[0][1] == grid [0][2]:
return True
if grid[0][1] == grid[0][2] == grid [0][3]:
return True
if grid[0][2] == grid[0][3] == grid [0][4]:
return True
if grid[0][3] == grid[0][4] == grid [0][5]:
return True
if grid[1][0] == grid[1][1] == grid [1][2]:
return True
if grid[1][1] == grid[1][2] == grid [1][3]:
return True
if grid[1][2] == grid[1][3] == grid [1][4]:
return True
if grid[1][3] == grid[1][4] == grid [1][5]:
return True
if grid[2][0] == grid[2][1] == grid [2][2]:
return True
if grid[2][1] == grid[2][2] == grid [2][3]:
return True
if grid[2][2] == grid[2][3] == grid [2][4]:
return True
if grid[2][3] == grid[2][4] == grid [2][5]:
return True
if grid[3][0] == grid[3][1] == grid [3][2]:
return True
if grid[3][1] == grid[3][2] == grid [3][3]:
return True
if grid[3][2] == grid[3][3] == grid [3][4]:
return True
if grid[3][3] == grid[3][4] == grid [3][5]:
return True
if grid[4][0] == grid[4][1] == grid [4][2]:
return True
if grid[4][1] == grid[4][2] == grid [4][3]:
return True
if grid[4][2] == grid[4][3] == grid [4][4]:
return True
if grid[4][3] == grid[4][4] == grid [4][5]:
return True
if grid[5][0] == grid[5][1] == grid [5][2]:
return True
if grid[5][1] == grid[5][2] == grid [5][3]:
return True
if grid[5][2] == grid[5][3] == grid [5][4]:
return True
if grid[5][3] == grid[5][4] == grid [5][5]:
return True
if grid[0][0] == grid[1][0] == grid [2][0]:
return True
if grid[1][0] == grid[2][0] == grid [3][0]:
return True
if grid[2][0] == grid[3][0] == grid [4][0]:
return True
if grid[3][0] == grid[4][0] == grid [5][0]:
return True
if grid[0][1] == grid[1][1] == grid [2][1]:
return True
if grid[1][1] == grid[2][1] == grid [3][1]:
return True
if grid[2][1] == grid[3][1] == grid [4][1]:
return True
if grid[3][1] == grid[4][1] == grid [5][1]:
return True
if grid[0][2] == grid[1][2] == grid [2][2]:
return True
if grid[1][2] == grid[2][2] == grid [3][2]:
return True
if grid[2][2] == grid[3][2] == grid [4][2]:
return True
if grid[3][2] == grid[4][2] == grid [5][2]:
return True
if grid[0][3] == grid[1][3] == grid [2][3]:
return True
if grid[1][3] == grid[2][3] == grid [3][3]:
return True
if grid[2][3] == grid[3][3] == grid [4][3]:
return True
if grid[3][3] == grid[4][3] == grid [5][3]:
return True
if grid[0][4] == grid[1][4] == grid [2][4]:
return True
if grid[1][4] == grid[2][4] == grid [3][4]:
return True
if grid[2][4] == grid[3][4] == grid [4][4]:
return True
if grid[3][4] == grid[4][4] == grid [5][4]:
return True
if grid[0][5] == grid[1][5] == grid [2][5]:
return True
if grid[1][5] == grid[2][5] == grid [3][5]:
return True
if grid[2][5] == grid[3][5] == grid [4][5]:
return True
if grid[3][5] == grid[4][5] == grid [5][5]:
return True
return False
def print_grid(grid):
print_row(grid,1)
print('-----------')
print_row(grid,2)
print('-----------')
print_row(grid,4)
print('-----------')
print_row(grid,4)
print('-----------')
print_row(grid,5)
print('-----------')
print_row(grid,6)
def print_row(grid, row):
output = get_state(grid,row,1)
output += '|' + get_state(grid, row, 2)
output += '|' + get_state(grid, row, 3)
output += '|' + get_state(grid, row, 4)
output += '|' + get_state(grid, row, 5)
output += '|' + get_state(grid, row, 5)
print (output)
ongoing = True
currentPlayer = 'X'
spaces = 36
while ongoing:
print_grid(grid)
print (currentPlayer + "'s turn")
print("Column?")
col = int(input())
print("Row?")
row = int(input())
current = get_state(grid,row,col)
if current != ' ':
print ("That spot is taken!")
else:
set_state(grid, row, col, currentPlayer)
spaces -= 1
if is_winner(grid):
print (currentPlayer + "'s wins!")
ongoing = False
else:
if currentPlayer == 'X':
currentPlayer = 'O'
elif currentPlayer == 'O':
curentPlayer = 'Y'
elif currentPlayer == 'Y':
currentPlayer = 'X'
if spaces == 0:
print("Stalemate!")
ongong = False
The is_winner(grid) function checks if 3 of the grid cells are the same. You initialized the grid to be 0, so the first player would always 'win'. One fix I suggest would be to initialize the list with different values. Another one would be to check (after finding that 3 cells are same) the values of the grid:
if grid[0][0] == grid[0][1] == grid[0][2]:
return grid[0][0] in ['X', 'O', 'Y']
The answer given by chucksys is good, although I would do it in a slightly different way. You need to determine that the 3 cells are the same, and not empty - so just check against your default value.
if grid[0][0] == grid[0][1] == grid[0][2] != 0:
return True
good luck with your game it's fun !!!! You can leave the code as it is. just make a different grid. one that contains a different value in every cell. That will prevent you from rewriting a lot of the game. At the beginning add the following code:grid = []
inner = []
b = 10
for i in xrange(6):
for ii in xrange(6):
inner.append(b)
b += 1
grid.append(inner)
inner = list()
This will make your grid, error proof from your checker function is_winner
There is also one small bug. curentPlayer = 'Y' change to currentPlayer = 'Y' near the end of the code
Hey everyone im new here and im trying to make a game called HiQ now i got the board drawn and everything and i can click on one of the pieces, but when i do the piece does change color and i get an error in the shell as well (listed below) im not sure why im getting this and i was hoping you guys could give me better insight. Ill provide my code below as well and it is coded in python 3, thank you
builtins.IndexError: list index out of range
boardcirc =[[0,0,0,1,1,1,0,0,0],
[0,0,0,1,1,1,0,0,0],
[0,0,0,1,1,1,0,0,0],
[1,1,1,1,1,1,1,1,1],
[1,1,1,1,2,1,1,1,1],
[1,1,1,1,1,1,1,1,1],
[0,0,0,1,1,1,0,0,0],
[0,0,0,1,1,1,0,0,0],
[0,0,0,1,1,1,0,0,0]]
def HiQ():
splash_screen()
make_board()
def make_board():
make_sqr()
make_circ()
get_click()
def get_click():
global count, boardcirc
while 1!=0:
count = count - 1
displaymessage("Pieces: " + str(count))
where = win.getMouse()
col = where.x//90
row = where.y//90
valid_move(row,col)
make_move(row,col)
def valid_move(row,col):
if boardcirc[row][col] == 0:
return False
if boardcirc[row-1][col] == 1 and boardcirc[row-2][col] == 1:
return True
if boardcirc[row+1][col] == 1 and boardcirc[row+2][col] == 1:
return True
if boardcirc[row][col-1] == 1 and boardcirc[row][col-2] == 1:
return True
if boardcirc[row][col+1] == 1 and boardcirc[row][col+2] == 1:
return True
def make_move(row,col):
while valid_move(row,col) == True:
col = (col*85)+42
row = (row*85)+42
circ = Circle(Point(col,row),35)
circ.setFill("white")
circ.draw(win)
thats everything that applies to the error
For your valid_move(row,col), you can't have all those if statements.
Instead of doing this, use elif's after the initial if statement, and don't forget to write an else statement
if boardcirc[row][col] == 0:
return False
if boardcirc[row-1][col] == 1 and boardcirc[row-2][col] == 1:
return True
elif boardcirc[row+1][col] == 1 and boardcirc[row+2][col] == 1:
return True
elif boardcirc[row][col-1] == 1 and boardcirc[row][col-2] == 1:
return True
elif boardcirc[row][col+1] == 1 and boardcirc[row][col+2] == 1:
return True
else:
return False