• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Sep 15th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. print("Szanowni Gracze oto najwspanialsza na świecie wersja gry w kółko i krzyżyk.Plansza składa się z\
2. 9 pól które są ponumerowe od 1 do 9\n Będziecie na zmianę proszeni o wybór pola. Pierwszy gracz\
3. będzie używać krzyżyków, drugi gracza będzie używać kółek.\
4.  Pola ponumerowane są według schematu poniżej")\
5.
6. line_1=["1","2","3"]
7. line_2=["4","5","6"]
8. line_3=["7","8","9"]
9.
10. def print_board():
11.     print(line_1)
12.     print(line_2)
13.     print(line_3)
14.
15. print_board()
16. what_is_actually_in_field = []
17. what_is_not_actually_in_field = ["0","1", "2", "3", "4", "5", "6", "7", "8", "9"]
18.
19.
20.
21. def is_field_taken():
22.     if move in what_is_actually_in_field: #Move nie jest argumentem funkcji make_move, tylko wartością zmienną w tej funkcji
23.         return True
24.     else:
25.         return False
26.
27. def win_check(current_player):
28.
29.     if line_1 == (current_player,current_player,current_player):
30.         return True
31.     elif line_2 == (current_player,current_player,current_player):
32.         return True
33.     elif line_3 == (current_player,current_player,current_player):
34.          return True
35.     elif line_1[0] == current_player and line_2[0] == current_player and line_3[0] == current_player:
36.          return True
37.     elif line_1[1] == current_player and line_2[1] == current_player and line_3[1] == current_player:
38.          return True
39.     elif line_1[2] == current_player and line_2[2] == current_player and line_3[2] == current_player:
40.         return True
41.     elif line_1[0] == current_player and line_2[1] == current_player and line_3[2] == current_player:
42.         return True
43.     elif line_1[2] == current_player and line_2[1] == current_player and line_3[0] == current_player:
44.          return True
45.
46.
47. def make_move (player):
48.     global what_is_actually_in_field
49.     global prompt_begin
50.     global sign
51.     global move
52.
53.     if player == "X":
54.         prompt_begin = "Pierwszy"
55.         sign = "X"
56.     else:
57.         prompt_begin = "Drugi"
58.         sign = "O"
59.     move = input("{} graczu wybierz prosze cyfre od 1 do 9 aby dodac {}: ".format(prompt_begin,sign))
60.
61. def check_which_field_is_taken (player):
62.     global line_1
63.     global line_2
64.     global line_3
65.     k = 0
66.     while k < 100:
67.         if move == "1":
68.             if is_field_taken() == False:
69.                 line_1[0] = player
70.                 what_is_actually_in_field.append(move)
71.                 what_is_not_actually_in_field.remove(move)
72.                 break
73.             else:
74.                 print("Pole jest już zajęte")
75.                 make_move(player)
76.         elif move == "2":
77.             if is_field_taken() == False:
78.                 line_1[1] = player
79.                 what_is_actually_in_field.append(move)
80.                 what_is_not_actually_in_field.remove(move)
81.                 break
82.             else:
83.                 print("Pole jest już zajęte")
84.                 make_move(player)
85.         elif move == "3":
86.             if is_field_taken() == False:
87.                 line_1[2] = player
88.                 what_is_actually_in_field.append(move)
89.                 what_is_not_actually_in_field.remove(move)
90.                 break
91.             else:
92.                 print("Pole jest już zajęte")
93.                 make_move(player)
94.         elif move == "4":
95.             if is_field_taken() == False:
96.                 line_2[0] = player
97.                 what_is_actually_in_field.append(move)
98.                 what_is_not_actually_in_field.remove(move)
99.                 break
100.             else:
101.                 print("Pole jest już zajęte")
102.                 make_move(player)
103.         elif move == "5":
104.             if is_field_taken() == False:
105.                 line_2[1] = player
106.                 what_is_actually_in_field.append(move)
107.                 what_is_not_actually_in_field.remove(move)
108.                 break
109.             else:
110.                 print("Pole jest już zajęte")
111.                 make_move(player)
112.         elif move=="6":
113.             if is_field_taken() == False:
114.                 line_2[2] = player
115.                 what_is_actually_in_field.append(move)
116.                 what_is_not_actually_in_field.remove(move)
117.                 break
118.             else:
119.                 print("Pole jest już zajęte")
120.                 make_move(player)
121.         elif move =="7":
122.             if is_field_taken()  == False:
123.                 line_3[0] = player
124.                 what_is_actually_in_field.append(move)
125.                 what_is_not_actually_in_field.remove(move)
126.                 break
127.             else:
128.                 print("Pole jest już zajęte")
129.                 make_move(player)
130.         elif move == "8":
131.             if is_field_taken() == False:
132.                 line_3[1] = player
133.                 what_is_actually_in_field.append(move)
134.                 what_is_not_actually_in_field.remove(move)
135.                 break
136.             else:
137.                 print("Pole jest już zajęte")
138.                 make_move(player)
139.         elif move == "9":
140.             if is_field_taken() == False:
141.                 line_3[2] = player
142.                 what_is_actually_in_field.append(move)
143.                 what_is_not_actually_in_field.remove(move)
144.                 break
145.             else:
146.                 print("Pole jest już zajęte")
147.                 make_move(player)
148.         else:
149.             print("Graczu wybrałeś cyfrę z poza zakresu 1-9. Spróbuj jeszcze raz")
150.
151.         k+= 1
152.
153. ooo_move_digit = 0
154.
155. def ooo_xxx_move (current_player):
156.     global ooo_move_digit
157.     if line_1[0] == current_player and line_1[1] == current_player and "3" not in what_is_actually_in_field:
158.         ooo_move_digit = "3"
159.         # Gdy zamiast funkcji próbuję tylko podać wartość computer_move pojawia się błąd
160.     elif line_1[0] == current_player and line_1[2] == current_player and "2" not in what_is_actually_in_field:
161.         ooo_move_digit = "2"
162.     elif line_1[1] == current_player and line_1[2] == current_player and "1" not in what_is_actually_in_field:
163.         ooo_move_digit = "1"
164.     elif line_2[0] == current_player and line_2[1] == current_player and "6" not in what_is_actually_in_field:
165.         ooo_move_digit = "6"
166.     elif line_2[0] == current_player and line_2[2] == current_player and "5" not in what_is_actually_in_field:
167.         ooo_move_digit = "5"
168.     elif line_2[1] == current_player and line_2[2] == current_player and "4" not in what_is_actually_in_field:
169.         ooo_move_digit = "4"
170.     elif line_3[0] == current_player and line_3[1] == current_player and "9" not in what_is_actually_in_field:
171.         ooo_move_digit = "9"
172.     elif line_2[2] == current_player and line_3[2] == current_player and "3" not in what_is_actually_in_field:
173.         ooo_move_digit  = "3"
174.     elif line_1[2] == current_player and line_2[1] == current_player and "3" not in what_is_actually_in_field:
175.         ooo_move_digit = "3"
176.     elif line_3[0] == current_player and line_3[2] == current_player and "8" not in what_is_actually_in_field:
177.         ooo_move_digit = "8"
178.     elif line_3[1] == current_player and line_3[2] == current_player and "7" not in what_is_actually_in_field:
179.         ooo_move_digit = "7"
180.     elif line_1[0] == current_player and line_2[0] == current_player and "7" not in what_is_actually_in_field:
181.         ooo_move_digit = "7"
182.     elif line_1[0] == current_player and line_3[0] == current_player and "4" not in what_is_actually_in_field:
183.         ooo_move_digit = "4"
184.     elif line_2[0] == current_player and line_3[0] == current_player and "1" not in what_is_actually_in_field:
185.         ooo_move_digit = "1"
186.     elif line_1[1] == current_player and line_2[1] == current_player and "8" not in what_is_actually_in_field:
187.         ooo_move_digit = "8"
188.     elif line_1[1] == current_player and line_3[1] == current_player and "5" not in what_is_actually_in_field:
189.         ooo_move_digit = "5"
190.     elif line_2[1] == current_player and line_3[1] == current_player and "2" not in what_is_actually_in_field:
191.         ooo_move_digit = "2"
192.     elif line_1[2] == current_player and line_2[2] == current_player and "9" not in what_is_actually_in_field:
193.         ooo_move_digit = "9"
194.     elif line_1[2] == current_player and line_3[2] == current_player and "6" not in what_is_actually_in_field:
195.         ooo_move_digit = "6"
196.     elif line_1[0] == current_player and line_2[1] == current_player and "9" not in what_is_actually_in_field:
197.         ooo_move_digit = "9"
198.     elif line_1[0] == current_player and line_3[2] == current_player and "5" not in what_is_actually_in_field:
199.         ooo_move_digit = "5"
200.     elif line_2[1] == current_player and line_3[2] == current_player and "1" not in what_is_actually_in_field:
201.         ooo_move_digit = "1"
202.     elif line_1[2] == current_player and line_2[1] == current_player and "7" not in what_is_actually_in_field:
203.         ooo_move_digit = "7"
204.     elif line_1[2] == current_player and line_3[0] == current_player and "5" not in what_is_actually_in_field:
205.         ooo_move_digit = "5"
206.     else:
207.         None
208.
209.
210. def random_move ():
211.     import random
212.     random_move = random.choice(what_is_not_actually_in_field)
213.     random_move = str(random_move)
214.     applying_automated_move ("O",random_move)
215.
216.
217. def automated_move ():
218.     ooo_xxx_move("O")
219.     if ooo_move_digit != 0:
220.         applying_automated_move("O", ooo_move_digit) #Błąd
221.         return
222.     ooo_xxx_move("X")
223.     if ooo_move_digit != 0:
224.         applying_automated_move("O", ooo_move_digit)
225.         return
226.     random_move()
227.
228.
229. def applying_automated_move (current_player,computer_move):
230.     global line_1
231.     global line_2
232.     global line_3
233.     global what_is_actually_in_field
234.
235.     if computer_move == "1":
236.         line_1[0] = current_player
237.     elif computer_move == "2":
238.         line_1[1] = current_player
239.     elif computer_move == "3":
240.         line_1[2] = current_player
241.     elif computer_move  == "4":
242.         line_2[0] = current_player
243.     elif computer_move  == "5":
244.         line_2[1] = current_player
245.     elif computer_move == "6":
246.         line_2[2] = current_player
247.     elif computer_move == "7":
248.         line_3[0] = current_player
249.     elif computer_move == "8":
250.         line_3[1] = current_player
251.     elif computer_move == "9":
252.         line_3[2] = current_player
253.     print ("Comp move:", computer_move)
254.     what_is_actually_in_field.append(computer_move)
255.     what_is_not_actually_in_field.remove(computer_move)
256.
257.
258.
259. def automated_last_move (player,last_move):
260.     global line_1
261.     global line_2
262.     global line_3
263.     global what_is_actually_in_field
264.
265.     k = 0
266.     while k < 100:
267.
268.         if last_move == "1":
269.             line_1[0] = player
270.             what_is_actually_in_field.append(last_move)
271.             break
272.         elif last_move == "2":
273.             line_1[1] = player
274.             what_is_actually_in_field.append(last_move)
275.             break
276.         elif last_move == "3":
277.             line_1[2] = player
278.             what_is_actually_in_field.append(last_move)
279.             break
280.         elif last_move  == "4":
281.             line_2[0] = player
282.             what_is_actually_in_field.append(last_move)
283.             break
284.         elif last_move  == "5":
285.             line_2[1] = player
286.             what_is_actually_in_field.append(last_move)
287.             break
288.         elif last_move == "6":
289.             line_2[2] = player
290.             what_is_actually_in_field.append(last_move)
291.             print ("znacznik 1")
292.             break
293.         elif last_move == "7":
294.             line_3[0] = player
295.             what_is_actually_in_field.append(last_move)
296.             break
297.         elif last_move == "8":
298.             line_3[1] = player
299.             what_is_actually_in_field.append(last_move)
300.             break
301.         elif last_move == "9":
302.             line_3[2] = player
303.             what_is_actually_in_field.append(last_move)
304.             break
305.
306.
307.     k+= 1
308. i = 0
309. while i < 4:
310.
311.     print (what_is_actually_in_field)
312.     print(what_is_not_actually_in_field)
313.     make_move("X")
314.     check_which_field_is_taken("X")
315.     print_board()
316.     if win_check("X") == True:
317.         print("Graczu pierwszy wygrałeś. Gratulacje!!!")
318.         break
319.
320.     print (what_is_actually_in_field)
321.     print(what_is_not_actually_in_field)
322.     automated_move()
323.     print ("Pole do ataku lub obrony: ", ooo_move_digit)
324.     print ("Wolne pola: ",what_is_not_actually_in_field)# Ruch automatyczny musi zostać wykonany przed ruchem manualnym
325.     print_board()
326.     if win_check("O") is True:
327.         print("Graczu drugi wygrałeś. Gratulacje!!!")
328.         break
329.     i+= 1
330.
331.
332. if i == 4:
333.     for last_move in range(1,10):# Mam tu inty od 1 do 9
334.         last_move = str(last_move) # last_move staje się tu stringiem
335.         if last_move not in what_is_actually_in_field:
336.             automated_last_move("X", last_move) # W tej funkcji cyfry są stringami
337.     if win_check("X") is True:
338.         print("Graczu pierwszy wygrałeś. Gratulacje!!!")
339.     else:
340.         print("Żaden z graczy nie wygrał")
341.
342. print_board()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top