943,895 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 326
  • Python RSS
May 18th, 2009
0

Doesn't declare a winner from 5 in a row, why not?

Expand Post »
python Syntax (Toggle Plain Text)
  1. #!/usr/bin/python
  2.  
  3. import os.path
  4.  
  5. n = 10
  6. allPositions = []
  7. state = []
  8. blackPairCap = 0
  9. whitePairCap = 0
  10. blackInaRow = 0
  11. whiteInaRow = 0
  12.  
  13. row0 = []
  14. row1 = []
  15. row2 = []
  16. row3 = []
  17. row4 = []
  18. row5 = []
  19. row6 = []
  20. row7 = []
  21. row8 = []
  22. row9 = []
  23.  
  24. allDirections = [[-1, 0],[1, 0],[0, -1],[0, 1],[-1, -1],[-1, 1],[1, -1],[1, 1]]
  25.  
  26. def displayBoard(playersTurn):
  27. print ""
  28. print " 0 1 2 3 4 5 6 7 8 9 "
  29. print " +--+--+--+--+--+--+--+--+--+--+--+"
  30. #------------------------------------------------#
  31. print "0" + " | " + str(row0[0]) + " " + str(row0[1]) + " " + str(row0[2]) + " " + str(row0[3]) + " " + str(row0[4]) + " " + str(row0[5]) + " " + str(row0[6]) + " " + str(row0[7]) + " " + str(row0[8]) + " " + str(row0[9]) + " " + "|"
  32. print "1" + " | " + str(row1[0]) + " " + str(row1[1]) + " " + str(row1[2]) + " " + str(row1[3]) + " " + str(row1[4]) + " " + str(row1[5]) + " " + str(row1[6]) + " " + str(row1[7]) + " " + str(row1[8]) + " " + str(row1[9]) + " " + "|"
  33. print "2" + " | " + str(row2[0]) + " " + str(row2[1]) + " " + str(row2[2]) + " " + str(row2[3]) + " " + str(row2[4]) + " " + str(row2[5]) + " " + str(row2[6]) + " " + str(row2[7]) + " " + str(row2[8]) + " " + str(row2[9]) + " " + "|"
  34. print "3" + " | " + str(row3[0]) + " " + str(row3[1]) + " " + str(row3[2]) + " " + str(row3[3]) + " " + str(row3[4]) + " " + str(row3[5]) + " " + str(row3[6]) + " " + str(row3[7]) + " " + str(row3[8]) + " " + str(row3[9]) + " " + "|"
  35. print "4" + " | " + str(row4[0]) + " " + str(row4[1]) + " " + str(row4[2]) + " " + str(row4[3]) + " " + str(row4[4]) + " " + str(row4[5]) + " " + str(row4[6]) + " " + str(row4[7]) + " " + str(row4[8]) + " " + str(row4[9]) + " " + "|"
  36. print "5" + " | " + str(row5[0]) + " " + str(row5[1]) + " " + str(row5[2]) + " " + str(row5[3]) + " " + str(row5[4]) + " " + str(row5[5]) + " " + str(row5[6]) + " " + str(row5[7]) + " " + str(row5[8]) + " " + str(row5[9]) + " " + "|"
  37. print "6" + " | " + str(row6[0]) + " " + str(row6[1]) + " " + str(row6[2]) + " " + str(row6[3]) + " " + str(row6[4]) + " " + str(row6[5]) + " " + str(row6[6]) + " " + str(row6[7]) + " " + str(row6[8]) + " " + str(row6[9]) + " " + "|"
  38. print "7" + " | " + str(row7[0]) + " " + str(row7[1]) + " " + str(row7[2]) + " " + str(row7[3]) + " " + str(row7[4]) + " " + str(row7[5]) + " " + str(row7[6]) + " " + str(row7[7]) + " " + str(row7[8]) + " " + str(row7[9]) + " " + "|"
  39. print "8" + " | " + str(row8[0]) + " " + str(row8[1]) + " " + str(row8[2]) + " " + str(row8[3]) + " " + str(row8[4]) + " " + str(row8[5]) + " " + str(row8[6]) + " " + str(row8[7]) + " " + str(row8[8]) + " " + str(row8[9]) + " " + "|"
  40. print "9" + " | " + str(row9[0]) + " " + str(row9[1]) + " " + str(row9[2]) + " " + str(row9[3]) + " " + str(row9[4]) + " " + str(row9[5]) + " " + str(row9[6]) + " " + str(row9[7]) + " " + str(row9[8]) + " " + str(row9[9]) + " " + "|"
  41. #------------------------------------------------#
  42. print " +--+--+--+--+--+--+--+--+--+--+--+\n"
  43. if (playersTurn % 2) == 0:
  44. print "WHITE's MOVE : \n"
  45. elif (playersTurn % 2) != 0:
  46. print "BLACK's MOVE : \n"
  47.  
  48. def createPositions():
  49. for i in range(0,n):
  50. for j in range(0,n):
  51. allPositions.append([i,j])
  52.  
  53. def winner():
  54. if (blackPairCap == 5):
  55. print "White is the winner!"
  56. return True
  57. elif (whitePairCap == 5):
  58. print "Black is the winner!"
  59. return True
  60. elif (blackInaRow >= 5):
  61. print "Black is the winner!"
  62. return True
  63. elif (whiteInaRow >= 5):
  64. print "White is the winner!"
  65. return True
  66.  
  67. player1 = ""
  68. player2 = ""
  69. comp1 = ""
  70. comp2 = ""
  71.  
  72. currentPlayers = []
  73.  
  74. FILES = []
  75.  
  76. def startGameMenu():
  77. print "Do you have a save file that you would like to run the game from?\n"
  78. saveFile = raw_input("y or n")
  79. saveFile = str(saveFile)
  80. if saveFile == "y":
  81. saveFileGame()
  82. if saveFile == "n":
  83. newGame()
  84.  
  85. def goesFirst():
  86. from random import choice
  87. return choice(currentPlayers)
  88.  
  89. def isBlank(row,col):
  90. if row == 0:
  91. if row0[col] == '.':
  92. return True
  93. elif row == 1:
  94. if row1[col] == '.':
  95. return True
  96. elif row == 2:
  97. if row2[col] == '.':
  98. return True
  99. elif row == 3:
  100. if row3[col] == '.':
  101. return True
  102. elif row == 4:
  103. if row4[col] == '.':
  104. return True
  105. elif row == 5:
  106. if row5[col] == '.':
  107. return True
  108. elif row == 6:
  109. if row6[col] == '.':
  110. return True
  111. elif row == 7:
  112. if row7[col] == '.':
  113. return True
  114. elif row == 8:
  115. if row8[col] == '.':
  116. return True
  117. elif row == 9:
  118. if row9[col] == '.':
  119. return True
  120.  
  121. def isNextTo(row,col):
  122. if row == 0:
  123. if (row0[col-1] != '.') or (row0[col+1] != '.') or (row1[col] != '.') or (row1[col-1] != '.') or (row1[col+1] != '.'):
  124. return True
  125. elif row == 1:
  126. if (row0[col-1] != '.') or (row0[col+1] != '.') or (row0[col] != '.') or (row1[col-1] != '.') or (row1[col+1] != '.') or (row2[col-1] != '.') or (row2[col] != '.') or (row2[col+1] != '.'):
  127. return True
  128. elif row == 2:
  129. if (row1[col-1] != '.') or (row1[col+1] != '.') or (row1[col] != '.') or (row2[col-1] != '.') or (row2[col+1] != '.') or (row3[col-1] != '.') or (row3[col] != '.') or (row3[col+1] != '.'):
  130. return True
  131. elif row == 3:
  132. if (row2[col-1] != '.') or (row2[col+1] != '.') or (row2[col] != '.') or (row3[col-1] != '.') or (row3[col+1] != '.') or (row4[col-1] != '.') or (row4[col] != '.') or (row4[col+1] != '.'):
  133. return True
  134. elif row == 4:
  135. if (row3[col-1] != '.') or (row3[col+1] != '.') or (row3[col] != '.') or (row4[col-1] != '.') or (row4[col+1] != '.') or (row5[col-1] != '.') or (row5[col] != '.') or (row5[col+1] != '.'):
  136. return True
  137. elif row == 5:
  138. if (row4[col-1] != '.') or (row4[col+1] != '.') or (row4[col] != '.') or (row5[col-1] != '.') or (row5[col+1] != '.') or (row6[col-1] != '.') or (row6[col] != '.') or (row6[col+1] != '.'):
  139. return True
  140. elif row == 6:
  141. if (row5[col-1] != '.') or (row5[col+1] != '.') or (row5[col] != '.') or (row6[col-1] != '.') or (row6[col+1] != '.') or (row7[col-1] != '.') or (row7[col] != '.') or (row7[col+1] != '.'):
  142. return True
  143. elif row == 7:
  144. if (row6[col-1] != '.') or (row6[col+1] != '.') or (row6[col] != '.') or (row7[col-1] != '.') or (row7[col+1] != '.') or (row8[col-1] != '.') or (row8[col] != '.') or (row8[col+1] != '.'):
  145. return True
  146. elif row == 8:
  147. if (row7[col-1] != '.') or (row7[col+1] != '.') or (row7[col] != '.') or (row8[col-1] != '.') or (row8[col+1] != '.') or (row9[col-1] != '.') or (row9[col] != '.') or (row9[col+1] != '.'):
  148. return True
  149. elif row == 9:
  150. if (row9[col-1] != '.') or (row9[col+1] != '.') or (row8[col] != '.') or (row8[col-1] != '.') or (row8[col+1] != '.'):
  151. return True
  152.  
  153. def countRow(color,row,col):
  154. if row == 0:
  155. for n in range(0,5):
  156. if (row0[col-(n+1)] == color) or (row0[col+(n+1)] == color) or (row1[col] == color) or (row1[col-(n+1)] == color) or (row1[col+(n+1)] == color):
  157. if color == "white":
  158. whiteInaRow += 1
  159. elif color == "black":
  160. blackInaRow += 1
  161. elif row == 1:
  162. for n in range(0,5):
  163. if (row0[col-(n+1)] == color) or (row0[col+(n+1)] == color) or (row0[col] == color) or (row1[col-(n+1)] == color) or (row1[col+(n+1)] == color) or (row2[col-(n+1)] == color) or (row2[col] == color) or (row2[col+(n+1)] == color):
  164. if color == "white":
  165. whiteInaRow += 1
  166. elif color == "black":
  167. blackInaRow += 1
  168. elif row == 2:
  169. for n in range(0,5):
  170. if (row1[col-(n+1)] == color) or (row1[col+(n+1)] == color) or (row1[col] == color) or (row2[col-(n+1)] == color) or (row2[col+(n+1)] == color) or (row3[col-(n+1)] == color) or (row3[col] == color) or (row3[col+(n+1)] == color):
  171. if color == "white":
  172. whiteInaRow += 1
  173. elif color == "black":
  174. blackInaRow += 1
  175. elif row == 3:
  176. for n in range(0,5):
  177. if (row2[col-(n+1)] == color) or (row2[col+(n+1)] == color) or (row2[col] == color) or (row3[col-(n+1)] == color) or (row3[col+(n+1)] == color) or (row4[col-(n+1)] == color) or (row4[col] == color) or (row4[col+(n+1)] == color):
  178. if color == "white":
  179. whiteInaRow += 1
  180. elif color == "black":
  181. blackInaRow += 1
  182. elif row == 4:
  183. for n in range(0,5):
  184. if (row3[col-(n+1)] == color) or (row3[col+(n+1)] == color) or (row3[col] == color) or (row4[col-(n+1)] == color) or (row4[col+(n+1)] == color) or (row5[col-(n+1)] == color) or (row5[col] == color) or (row5[col+(n+1)] == color):
  185. if color == "white":
  186. whiteInaRow += 1
  187. elif color == "black":
  188. blackInaRow += 1
  189. elif row == 5:
  190. for n in range(0,5):
  191. if (row4[col-(n+1)] == color) or (row4[col+(n+1)] == color) or (row4[col] == color) or (row5[col-(n+1)] == color) or (row5[col+(n+1)] == color) or (row6[col-(n+1)] == color) or (row6[col] == color) or (row6[col+(n+1)] == color):
  192. if color == "white":
  193. whiteInaRow += 1
  194. elif color == "black":
  195. blackInaRow += 1
  196. elif row == 6:
  197. for n in range(0,5):
  198. if (row5[col-(n+1)] == color) or (row5[col+(n+1)] == color) or (row5[col] == color) or (row6[col-(n+1)] == color) or (row6[col+(n+1)] == color) or (row7[col-(n+1)] == color) or (row7[col] == color) or (row7[col+(n+1)] == color):
  199. if color == "white":
  200. whiteInaRow += 1
  201. elif color == "black":
  202. blackInaRow += 1
  203. elif row == 7:
  204. for n in range(0,5):
  205. if (row6[col-(n+1)] == color) or (row6[col+(n+1)] == color) or (row6[col] == color) or (row7[col-(n+1)] == color) or (row7[col+(n+1)] == color) or (row8[col-(n+1)] == color) or (row8[col] == color) or (row8[col+(n+1)] == color):
  206. if color == "white":
  207. whiteInaRow += 1
  208. elif color == "black":
  209. blackInaRow += 1
  210. elif row == 8:
  211. for n in range(0,5):
  212. if (row7[col-(n+1)] == color) or (row7[col+(n+1)] == color) or (row7[col] == color) or (row8[col-(n+1)] == color) or (row8[col+(n+1)] == color) or (row9[col-(n+1)] == color) or (row9[col] == color) or (row9[col+(n+1)] == color):
  213. if color == "white":
  214. whiteInaRow += 1
  215. elif color == "black":
  216. blackInaRow += 1
  217. elif row == 9:
  218. for n in range(0,5):
  219. if (row9[col-(n+1)] == color) or (row9[col+(n+1)] == color) or (row8[col] == color) or (row8[col-(n+1)] == color) or (row8[col+(n+1)] == color):
  220. if color == "white":
  221. whiteInaRow += 1
  222. elif color == "black":
  223. blackInaRow += 1
  224.  
  225. def inGameMenu():
  226. turn = 0
  227. displayBoard(turn)
  228. while not winner():
  229. move = raw_input("Enter move in row, column form (i.e. '6 6'): ")
  230. moveRow = int(move[0])
  231. moveCol = int(move[2])
  232. if turn == 0:
  233. if moveRow == 0:
  234. if turn % 2 == 0:
  235. row0[moveCol] = 'w'
  236. else:
  237. row0[moveCol] = 'b'
  238. elif moveRow == 1:
  239. if turn % 2 == 0:
  240. row1[moveCol] = 'w'
  241. else:
  242. row1[moveCol] = 'b'
  243. elif moveRow == 2:
  244. if turn % 2 == 0:
  245. row2[moveCol] = 'w'
  246. else:
  247. row2[moveCol] = 'b'
  248. elif moveRow == 3:
  249. if turn % 2 == 0:
  250. row3[moveCol] = 'w'
  251. else:
  252. row3[moveCol] = 'b'
  253. elif moveRow == 4:
  254. if turn % 2 == 0:
  255. row4[moveCol] = 'w'
  256. else:
  257. row4[moveCol] = 'b'
  258. elif moveRow == 5:
  259. if turn % 2 == 0:
  260. row5[moveCol] = 'w'
  261. else:
  262. row5[moveCol] = 'b'
  263. elif moveRow == 6:
  264. if turn % 2 == 0:
  265. row6[moveCol] = 'w'
  266. else:
  267. row6[moveCol] = 'b'
  268. elif moveRow == 7:
  269. if turn % 2 == 0:
  270. row7[moveCol] = 'w'
  271. else:
  272. row7[moveCol] = 'b'
  273. elif moveRow == 8:
  274. if turn % 2 == 0:
  275. row8[moveCol] = 'w'
  276. else:
  277. row8[moveCol] = 'b'
  278. elif moveRow == 9:
  279. if turn % 2 == 0:
  280. row9[moveCol] = 'w'
  281. else:
  282. row9[moveCol] = 'b'
  283. if isNextTo(moveRow,moveCol) and isBlank(moveRow,moveCol):
  284. if moveRow == 0:
  285. if turn % 2 == 0:
  286. row0[moveCol] = 'w'
  287. else:
  288. row0[moveCol] = 'b'
  289. elif moveRow == 1:
  290. if turn % 2 == 0:
  291. row1[moveCol] = 'w'
  292. else:
  293. row1[moveCol] = 'b'
  294. elif moveRow == 2:
  295. if turn % 2 == 0:
  296. row2[moveCol] = 'w'
  297. else:
  298. row2[moveCol] = 'b'
  299. elif moveRow == 3:
  300. if turn % 2 == 0:
  301. row3[moveCol] = 'w'
  302. else:
  303. row3[moveCol] = 'b'
  304. elif moveRow == 4:
  305. if turn % 2 == 0:
  306. row4[moveCol] = 'w'
  307. else:
  308. row4[moveCol] = 'b'
  309. elif moveRow == 5:
  310. if turn % 2 == 0:
  311. row5[moveCol] = 'w'
  312. else:
  313. row5[moveCol] = 'b'
  314. elif moveRow == 6:
  315. if turn % 2 == 0:
  316. row6[moveCol] = 'w'
  317. else:
  318. row6[moveCol] = 'b'
  319. elif moveRow == 7:
  320. if turn % 2 == 0:
  321. row7[moveCol] = 'w'
  322. else:
  323. row7[moveCol] = 'b'
  324. elif moveRow == 8:
  325. if turn % 2 == 0:
  326. row8[moveCol] = 'w'
  327. else:
  328. row8[moveCol] = 'b'
  329. elif moveRow == 9:
  330. if turn % 2 == 0:
  331. row9[moveCol] = 'w'
  332. else:
  333. row9[moveCol] = 'b'
  334. turn += 1
  335. displayBoard(turn)
  336.  
  337. def saveFileGame():
  338. fileName = raw_input("What is the name of the save file (with extension)? \n")
  339. FILES.append(fileName)
  340. f = open(fileName, 'r')
  341. lineList = f.readlines()
  342. counter = 0
  343. for line in lineList:
  344. if counter == 0:
  345. row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  346. if counter == 1:
  347. row1.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  348. if counter == 2:
  349. row2.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  350. if counter == 3:
  351. row3.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  352. if counter == 4:
  353. row4.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  354. if counter == 5:
  355. row5.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  356. if counter == 6:
  357. row6.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  358. if counter == 7:
  359. row7.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  360. if counter == 8:
  361. row8.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  362. if counter == 9:
  363. row9.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]])
  364. counter += 1
  365. f.close()
  366. player1 = "white"
  367. player2 = "black"
  368. currentPlayers.append(player1)
  369. currentPlayers.append(player2)
  370. inGameMenu()
  371.  
  372. def blankBoard():
  373. row0.extend(['.','.','.','.','.','.','.','.','.','.'])
  374. row1.extend(['.','.','.','.','.','.','.','.','.','.'])
  375. row2.extend(['.','.','.','.','.','.','.','.','.','.'])
  376. row3.extend(['.','.','.','.','.','.','.','.','.','.'])
  377. row4.extend(['.','.','.','.','.','.','.','.','.','.'])
  378. row5.extend(['.','.','.','.','.','.','.','.','.','.'])
  379. row6.extend(['.','.','.','.','.','.','.','.','.','.'])
  380. row7.extend(['.','.','.','.','.','.','.','.','.','.'])
  381. row8.extend(['.','.','.','.','.','.','.','.','.','.'])
  382. row9.extend(['.','.','.','.','.','.','.','.','.','.'])
  383.  
  384. def newGame():
  385. blankBoard()
  386. print "Welcome to Pente!\n"
  387. print "Would you like to play a new game?\n"
  388. answer = raw_input("y or n:")
  389. answer = str(answer)
  390. if (answer == "y"):
  391. numPlayers = raw_input("How many players are going to be playing? (1-4):\n")
  392. numPlayers = int(numPlayers)
  393. for p in range(0,numPlayers):
  394. print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n"
  395. player = raw_input("p1, p2, pc1, or pc2:")
  396. player = str(player)
  397. if (player == "p1"):
  398. currentPlayers.append(player1)
  399. elif (player == "p2"):
  400. currentPlayers.append(player2)
  401. elif (player == "pc1"):
  402. currentPlayers.append(comp1)
  403. elif (player == "pc2"):
  404. currentPlayers.append(comp2)
  405. print "Which color would you like to play as?\n"
  406. color = raw_input("b (black) or w (white):")
  407. color = str(color)
  408. if (color == "b"):
  409. currentPlayers[p] = "black"
  410. elif (color == "w"):
  411. currentPlayers[p] = "white"
  412. inGameMenu()
  413.  
  414. startGameMenu()
  415. inGameMenu()
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
gotm is offline Offline
33 posts
since May 2008
May 18th, 2009
0

Re: Doesn't declare a winner from 5 in a row, why not?

Oh my God, man; have you never heard of lists and loops?

row0, row2 etc. can become a list of lists called rows, and that code where you explicitly print each element of each row can be put into a simple loop.

No, this doesn't solve your problem, but code this messy is almost guaranteed to have issues.
Last edited by scru; May 18th, 2009 at 11:38 pm.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
May 19th, 2009
1

Re: Doesn't declare a winner from 5 in a row, why not?

Click to Expand / Collapse  Quote originally posted by gotm ...
python Syntax (Toggle Plain Text)
  1. [Snipped for brevity]
Your problems all stem from the fact that you aren't recognizing the 'scope' of your variables. You shouldn't be using global variables at all in fact, and your code could use a more coherent structure (for your own sake).

Here's a quick example of a better structure to use for your code:
python Syntax (Toggle Plain Text)
  1. #!/usr/bin/python
  2.  
  3. import os.path
  4. from random import choice
  5.  
  6. def displayBoard( ... ):
  7. ...
  8.  
  9. def createPositions( ... ):
  10. ...
  11.  
  12. ...
  13.  
  14. def main():
  15. # Initialize all your variables here
  16. win = False
  17.  
  18. while not win:
  19. # Call your 'game' functions
  20. ...
  21. win = winner()
  22.  
  23. # Print any final messages to the user, etc.
  24.  
  25. if __name__ == '__main__':
  26. main()

Every single one of your functions needs to be revamped to make use of local variables only. A function should be completely independent of the code outside the function. It should receive the inputs from the main code, do the work that it needs to do, and then return a result. It should not be using global variables willy-nilly because you'll run into many problems like you have in this code.

Also your functions should not be calling themselves. This is recursion and it's not useful in this type of situation. You should simply set up a while loop as I demonstrated above and continually call each function until the game has been won
Last edited by jlm699; May 19th, 2009 at 9:19 am.
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008
May 20th, 2009
0

Re: Doesn't declare a winner from 5 in a row, why not?

Thank you.
Reputation Points: 10
Solved Threads: 0
Light Poster
gotm is offline Offline
33 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: looping
Next Thread in Python Forum Timeline: WHY? improper syntax?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC