From 2b7004ad3467f1d7de1a7ab10043c1228b88bc4e Mon Sep 17 00:00:00 2001 From: Agata Halik Date: Thu, 8 Jun 2023 16:02:55 +0200 Subject: [PATCH] initial --- .idea/.gitignore | 8 + .idea/inspectionProfiles/Project_Default.xml | 12 + .../inspectionProfiles/profiles_settings.xml | 7 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/mojeszachy.iml | 10 + __pycache__/bishop.cpython-310.pyc | Bin 0 -> 500 bytes __pycache__/board.cpython-310.pyc | Bin 0 -> 5461 bytes __pycache__/game.cpython-310.pyc | Bin 0 -> 2341 bytes __pycache__/king.cpython-310.pyc | Bin 0 -> 492 bytes __pycache__/knight.cpython-310.pyc | Bin 0 -> 537 bytes __pycache__/pawn.cpython-310.pyc | Bin 0 -> 492 bytes __pycache__/piece.cpython-310.pyc | Bin 0 -> 801 bytes __pycache__/queen.cpython-310.pyc | Bin 0 -> 496 bytes __pycache__/rook.cpython-310.pyc | Bin 0 -> 492 bytes __pycache__/square.cpython-310.pyc | Bin 0 -> 1263 bytes bishop.py | 5 + board.py | 224 ++++++++++++++++++ game.py | 91 +++++++ king.py | 5 + knight.py | 5 + main.py | 28 +++ pawn.py | 5 + piece.py | 18 ++ queen.py | 5 + rook.py | 5 + square.py | 34 +++ 27 files changed, 474 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/mojeszachy.iml create mode 100644 __pycache__/bishop.cpython-310.pyc create mode 100644 __pycache__/board.cpython-310.pyc create mode 100644 __pycache__/game.cpython-310.pyc create mode 100644 __pycache__/king.cpython-310.pyc create mode 100644 __pycache__/knight.cpython-310.pyc create mode 100644 __pycache__/pawn.cpython-310.pyc create mode 100644 __pycache__/piece.cpython-310.pyc create mode 100644 __pycache__/queen.cpython-310.pyc create mode 100644 __pycache__/rook.cpython-310.pyc create mode 100644 __pycache__/square.cpython-310.pyc create mode 100644 bishop.py create mode 100644 board.py create mode 100644 game.py create mode 100644 king.py create mode 100644 knight.py create mode 100644 main.py create mode 100644 pawn.py create mode 100644 piece.py create mode 100644 queen.py create mode 100644 rook.py create mode 100644 square.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..1c2fda5 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c00de87 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..dd4c951 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2332a7b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..83b84cd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/mojeszachy.iml b/.idea/mojeszachy.iml new file mode 100644 index 0000000..858c4d5 --- /dev/null +++ b/.idea/mojeszachy.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/__pycache__/bishop.cpython-310.pyc b/__pycache__/bishop.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ad1c0cfc28715bfb25b412dca8819eaa04918ad6 GIT binary patch literal 500 zcmYjN!AiqG5S`s5C9N%j^eE`HmwteVhzNp*B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YZx`N7G*;9jQjUdg!yy@7cYXZGE8}{Qq^*TZrfP@SPx> zWo-`Hi34$p_~Z6DKkh>VS|g(G4Mup9bpoOhHlfov7`<7__fF7Qz za_J_3d>TOh^RyjrdnU3lcH}!X?GNq9WI!M9JEoDjwy8Qg-umFTT-7KqTB zA7TA=>s;X7Pm)ZZb8xz$?+Jv@5}SOnyg`-d6svd%EI`Yh_S#xJjB*E`C!%B!ROzWd zRhWG+m5sytMx0mZb4Rz`4{FGF%hNiMRZuHje1RqA3hJe$SQvahtMXZ&3I)Da3-2*2 zQT-TUT9&581?ag@x#(#6V-95ctMZbe_x>Zwq*ovu9KGlYaGDQd@`?Pa>C~}zHeqZ0 z%QHPOZ#J;E`eNQXZO+T{C}(lmbHcJVXEiU5<6@(s4=%*gVVHX%wu)#2x1uoj!w?_x z`r4yt-{9M}qGhT+An`E??(9TRw^bE_Oewv&i%s9Hx@XM9BTIKb>j_jUDC64cyr{m9)#{We!XDn?2O@eRH4Y3YiF F{5LI5mdpSE literal 0 HcmV?d00001 diff --git a/__pycache__/game.cpython-310.pyc b/__pycache__/game.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5b9f51654b418434aa8a7eea169a79007532cce3 GIT binary patch literal 2341 zcma)8Pj4GV6rZ>MyxurYNkbup21B935>&LMMXD-Pm5M?uh0vZ@g|0T9ZM^=oYtOD5 z#c~l+`T>ym0?9E4z5t(s^V}*q^SbLS=F&Yl(8+Q z9t*zSB6aq$P`Qh(_zb&*g}_;8ap2ZVh7^h}bhyhs)LmZTK8_x*B6T302XQ}X0ls+j zkW7r0Jbf1#w= z{xt8uGspJsnb}s6?cZazSBCB49NT+mW_!PD;R-d5_)rcEG>)bu|PRGA_WqnG=Tu_ma@WoV**QTl>!1XDeR|z+!jvBw5 z(lM8CbLy$_)|Ae&gs(zJTp5*0tnDrg9eUDvSy_kTF{Evo6;Iszt-&ld}Sm1 z$*&IMB~?vNqM56wv|q>dw2ew>s?#1|WwA;d^U2~^mz3@p-8Q;wbjRqP(OsigN}nnX zayZyrY*dLV2QFrgw?3|IKKAprfvm0ypP;88;nY67bR}QK#Y@C zx|5|{Y2!A8{xgyHBiw{=K}mWiLa)pfSjEw74&`GQ&>lu2eIEA&CE)2TTk6N%L~XR5 z^cd%;8?O%M%j^ K8&E^KW$QnONeD{- literal 0 HcmV?d00001 diff --git a/__pycache__/king.cpython-310.pyc b/__pycache__/king.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7a4fbc58b517f0eb0875936b83c7843476ab90a8 GIT binary patch literal 492 zcmYjN!AiqG5S`s5lGf%@dQ|Y*OFuwFJP3k95xj-M5VBj1-83R%K=J!ot5>?e7_`GDa7D+SQBt6Ufn3Bwzzry=ybUN% zi?tU^hjwOu9Y({jRMqjFgt9fn(W(HEg{pY_{ZeLl}srGp1JwN`BaiO*Fk0 Uy%A!%3orKbF9jjX8a)`uKg*VBTL1t6 literal 0 HcmV?d00001 diff --git a/__pycache__/knight.cpython-310.pyc b/__pycache__/knight.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..30a2b29f8d13b96178e2b3286538b09ceb78dd49 GIT binary patch literal 537 zcmYk3&q~8U5XNWn&sbUn=~3_;kUoHjcn}1IBJ>stOUQ0*?WU=_DcItzg+72UpvS(_ zUOo8=o}5Wa=|CpmOftXyGATQq7ErkAU4GL2hl}F~sJNrcUQv=DQA2?#B5O~3g`fHe z4`a8)Z4-cB}#7- zr~VcKNCRT}E_#|xUdC1K9RXOgPv+QjN)@c(i>5#D+heCR>GfSStw$5jg?2Gl#>GNR zW|K+?Y6Vv5kqh%umu83VRES(>)(WwMzstw#;k~lcs+SVYmXDXi2G^S}&B@+? zWhdvjI%`b!4*ZbMnq`F&!nK4bO1aRi+d|Mvbn~RfxX%9MTxl(YX%n$Y{GUvR)8SiL t#L&gM(@#Pd&Uw{_ZMewR+cvzF`h_D_O=XsgZyGbVNR^E!wV{n&{0Du9b`k&p literal 0 HcmV?d00001 diff --git a/__pycache__/pawn.cpython-310.pyc b/__pycache__/pawn.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ba9fd2ab06541159d54d4d5c01d6fef54338f63d GIT binary patch literal 492 zcmYjN!AiqG5S`s5lGf%@JSuqYr5_+79t6QdDR>KoA?$9kx@lrIRa(5Y(BIHwKgD0z zt0#ZKgE*5G$-vIeo8-NDvqh40f#UbG)-QB_F=$6f;F^v*r=&p(3%N*zfLqW~2OH3V z5$hn8I=qKL^i6-kK=^1pGs-AN?FbIQol;>S6&g~xg{ja&%T1gHTL>X#rND>d>~*eW zi_SIsVHMY>RKptHiTfr#q#$?1lOrFNL>x#TxkYIzA0y7@vl@|Fp)+>sBURX<+6mu5 zR5o)CaR)zVcNdczL;yLpyH;BHA zm=}6sx$Yr8FEYFT(unxvFjX0A5vya;+ouj!Jx;t~vn8(^!-;4*BYKsn8S%5T0HC#5leqoJ560MdKzF6+$Qy2&5Dzr0cAcR+eWWPJFgmJBjY(jywn{ z^DMl7Vjz049(w4L^fADYWPk^hBeKEAQWv`5ViU2>sooNI zF9`-QfPz61iqAkuNeR6{qP&piDSBl22rEE;($Zl0-UioaWv?H857k$~(sb~F8SD#Ek?@dT>2j-B(kLRba*6(z8 z(KqdS)12#WmltQ-b<6V{w_6)2Rn}#%6wlJl2|_V`kr#_t?&fav<0-7*xQSTjJ-8hl zkutzJd=rDX6@pH&f;+KHr8yvv4fD3uHIm5(&3vB2wKzh;F^_WmJtsHParz^%dpvgV z$5-%@CSslATnn7pt=<(koFo;lJPCIGTQEUg>0Xb!eL?}QW-NA#vF5&enTEVAzKl{f zR`dujE7lXGzFg+j=rJ>{!^<$7aIYfY!|)mh#ozUkuveJ8f#37@-aB=PFSNqjq=)U`}13AVLX|*ue}XO0f+iZwEd^tmN6?p;Bs* zh!&q~HpDV!;8F=2cz5JC{1E8uIii@@V9Cspuz{&^RoIYdzL=LpuH_r0XEsPOofUhu z9il|X#t`k{=j`rcdZWxsndQ?odsb#0Cr_(stv1eA#nEBBVIKorpVSV=|LOrxTEwX$ zvR$Gyla=PWN3^VB-F&H4Z2vGfQCbrf$4; literal 0 HcmV?d00001 diff --git a/__pycache__/rook.cpython-310.pyc b/__pycache__/rook.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f15ec92082cb69cdc1371af90ec8bc75e5364182 GIT binary patch literal 492 zcmYjN!AiqG5S`s5lGf%@dQ|Y*OFuwFJP3k^B6>z}cl>#5$TRYEX zi_SIsVHMY>RKo_|i2Ewur6702lVcxNL>x*Vxn-#eF)z{ z%uVJT;s^Yk-kwjcwVT(roD}v+yLFa7t|lxtDp%FfVYp)#eX&m1-soRD;yH_~(1^Z^ zSXi|*T=x*4mzmjrX+(T-n3`*25UXR-+ouj!Jx;t~vn8(^!$35hF}+Gu^21haqUp8h UjS$m)e6gQ@DF`{%=)pk#0TDTAqW}N^ literal 0 HcmV?d00001 diff --git a/__pycache__/square.cpython-310.pyc b/__pycache__/square.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..84ee9b4bd840f0ea33b47b165f2b79d779dacd53 GIT binary patch literal 1263 zcmZ`&OK%e~5FUFUb+&m?)Y1cw3zxm{0}w(8s#fBVOL~fmtYy74+dMY4H$bE1)cg>7 z%wO^iaq77@E@fu7Nz+m+&3J5&{eAw%&KivXu-W{(`sD!prono{Ie3R=w$L4b0>$QN z=e!4scOi6QoWIjnJKp1T0zIan$5m5t<;+>nQLggl&~ufqHn8`UP&Mp*6{t<@Hxi-h zsxgOi)~hLo2rcV(Pp6SiIc2R&ENg$3(`j&*eQ&H8aR zoQ}rUo1{scgsyc>GW?>6ucp(qhi(CS1G_&jKE6KMOUxk8CP$;}Br&rn?w=i*lF6&d znH5r|<209&_8T9a&wLiJS*v3EYPlXWTw6AZSFB0W0!~oWDWcM4Nz#SW**^?f$p$+* zxujG%fkRvCM@E*npkWCfFqgS}*1iE>CB%fbY!t81U*e#EpKyWYMEoW)VJEy`14p+@ zE~p+U81l|x=;%#MFF9EcbPm-S5%JUXaFInxjDU25+&wDIWHiaoWTq=ZB>5Fdx>M=3eWTai ztpC!|ErK9m-6r=C;`ZIM$`M}jJ2FmHeDOWC*%j;ay36~_q{$Z&{$gLacV`Clk_Z1S^SbokTt)3AK-A(W| zK4pH5?`ip%mpPg^g#o?(aWqP#w1JePOihOr*QLb&F|1Z}4O7>u^N5Cz(b>AmqdbjA zN#4(t-lh55s+AEvYfXQJ%#hRq0xmq^3s-pDZ?bZ=ga3mv9@=ijn~K-l@(kj=1%Ck^ C!S+}H literal 0 HcmV?d00001 diff --git a/bishop.py b/bishop.py new file mode 100644 index 0000000..dd36d0e --- /dev/null +++ b/bishop.py @@ -0,0 +1,5 @@ +from piece import Piece + +class Bishop(Piece): + def __init__(self, color): + super().__init__("bishop", color) \ No newline at end of file diff --git a/board.py b/board.py new file mode 100644 index 0000000..fc405d6 --- /dev/null +++ b/board.py @@ -0,0 +1,224 @@ +from square import Square +from pawn import Pawn +from knight import Knight +from bishop import Bishop +from rook import Rook +from queen import Queen +from king import King +import random + +class Board: + def __init__(self): + self.boardlist = [[0, 0, 0, 0, 0, 0, 0, 0] for x in range(8)] + #creating board + for row in range(8): + for column in range(8): + self.boardlist[row][column] = Square(row, column) + self._add_pieces('white') + self._add_pieces('black') + + def _add_pieces(self, color): + if color == 'white': + self.pawn_row = 6 + self.other_row = 7 + else: + self.pawn_row = 1 + self.other_row = 0 + #pawns + #self.boardlist[5][1] = Square(5, 1, King(color)) #DO USUNIĘCIA + for column in range(8): + self.boardlist[self.pawn_row][column] = Square(self.pawn_row, column, Pawn(color)) #do kazdego square przypisuje poczatkowy pawn + #rooks + self.boardlist[self.other_row][0] = Square(self.other_row, 0, Rook(color)) + self.boardlist[self.other_row][7] = Square(self.other_row, 7, Rook(color)) + #knigths + self.boardlist[self.other_row][1] = Square(self.other_row, 1, Knight(color)) + self.boardlist[self.other_row][6] = Square(self.other_row, 6, Knight(color)) + #bishops + self.boardlist[self.other_row][2] = Square(self.other_row, 2, Bishop(color)) + self.boardlist[self.other_row][5] = Square(self.other_row, 5, Bishop(color)) + #queen + self.boardlist[self.other_row][3] = Square(self.other_row, 3, Queen(color)) + #king + self.boardlist[self.other_row][4] = Square(self.other_row, 4, King(color)) + + def calc_moves(self, piece, row, column): + def knight_moves(): + #piece.delete_moves() + self.possible_moves = [ + (row + 2, column - 1), + (row + 2, column + 1), + (row + 1, column + 2), + (row - 1, column + 2), + (row - 2, column + 1), + (row - 2, column - 1), + (row - 1, column - 2), + (row + 1, column - 2) + ] + for self.possible_move in self.possible_moves: + self.possible_row, self.possible_column = self.possible_move + if Square.on_board(self.possible_row, self.possible_column): + if self.boardlist[self.possible_row][self.possible_column].empty_or_rival(piece.color): + self.final = (self.possible_row, self.possible_column) + piece.add_moves(self.final) + def pawn_moves(): + #piece.delete_moves() + if piece.moved == True: + self.steps = 1 + else: + self.steps = 2 + + if self.steps == 2: + self.final = row + (piece.pawn_direction * (self.steps)) + self.previous = row + (piece.pawn_direction * (self.steps - 1)) + if Square.on_board(self.final, column) is True: + if self.boardlist[self.final][column].has_piece() is False: + if self.boardlist[self.previous][column].has_piece() is False: + piece.add_moves((self.final, column)) + self.steps = 1 + self.final = row + (piece.pawn_direction * (self.steps)) + #problem z wierszem + #if self.final>7 or self.final<0 or column>7 or column <0: + #print(piece.name) + #print(self.final, column) + if Square.on_board(self.final, column) is True and self.boardlist[self.final][column].has_piece() is False: + piece.add_moves((self.final, column)) + + #diagonal + #czy wychodzi poza tablice i czy stoi rywal + self.possible_row = row + piece.pawn_direction + self.possible_columns = [] + self.possible_columns = [column-1, column+1] + for possible_column in self.possible_columns: + if Square.on_board(self.possible_row, possible_column) is True: + if self.boardlist[self.possible_row][possible_column].is_rival(piece.color) is True: + piece.add_moves((self.possible_row, possible_column)) + def straightline_moves(isvertical): + if isvertical is True: + self.direction = [ + (0, 1), + (0, -1), + (1, 0), + (-1, 0)] + else: + self.direction = [ + (1, 1), + (-1, -1), + (1, -1), + (-1, 1) + ] + for dir in self.direction: + self.left, self.right = dir + self.possible_row = row + self.left + self.possible_column = column + self.right + while True: + if Square.on_board(self.possible_row, self.possible_column) is True: + if self.boardlist[self.possible_row][self.possible_column].has_piece() is False: + piece.add_moves((self.possible_row, self.possible_column)) + self.possible_row = self.possible_row + self.left + self.possible_column = self.possible_column + self.right + elif self.boardlist[self.possible_row][self.possible_column].is_rival(piece.color) is True: + piece.add_moves((self.possible_row, self.possible_column)) + break + else: + break + else: + break + def king_moves(): + #piece.delete_moves() + self.direction = [ + (0, 1), + (0, -1), + (1, 0), + (-1, 0), + (1, 1), + (-1, -1), + (1, -1), + (-1, 1) + ] + for dir in self.direction: + self.left, self.right = dir + self.possible_row = row + self.left + self.possible_column = column + self.right + if Square.on_board(self.possible_row, self.possible_column) is True: + if self.boardlist[self.possible_row][self.possible_column].has_piece() is False: + piece.add_moves((self.possible_row, self.possible_column)) + elif self.boardlist[self.possible_row][self.possible_column].is_rival(piece.color) is True: + piece.add_moves((self.possible_row, self.possible_column)) + #calculate possible moves for specific piece + if piece.name == 'rook': + #piece.delete_moves() + straightline_moves(True) + elif piece.name == 'pawn': + pawn_moves() + elif piece.name == 'knight': + knight_moves() + elif piece.name == 'bishop': + #piece.delete_moves() + straightline_moves(False) + elif piece.name == 'queen': + #piece.delete_moves() + straightline_moves(True) + straightline_moves(False) + elif piece.name == 'king': + king_moves() + + def move_rival(self, from_row, from_column, to_row, to_column): + #update + self.x = self.board.boardlist[from_row][from_column].piece + self.board.boardlist[from_row][from_column].piece = None + if (self.board.boardlist[to_row][to_column].has_piece()): + if (self.board.boardlist[to_row][to_column].piece.name == 'king'): + self.board.boardlist[to_row][to_column].piece = self.x + return 1 + self.board.boardlist[to_row][to_column].piece = self.x + self.board.boardlist[to_row][to_column].piece.moved = True + self.board.boardlist[to_row][to_column].piece.delete_moves() + return 0 + + def move_boot(self, color): + self.boot_piece = [] + self.piece_row_column = [] + for r in range(0, 8): + for c in range(0, 8): + if self.board.boardlist[r][c].piece != None: + if self.board.boardlist[r][c].piece.color == color: + self.boot_piece.append(self.board.boardlist[r][c]) + #random piece + + self.value = random.randrange(0, len(self.boot_piece)) + self.initial = self.boot_piece[self.value] + while len(self.initial.piece.valid_moves) == 0: + self.value = random.randrange(0, len(self.boot_piece)) + self.initial = self.boot_piece[self.value] + self.initial_row=self.initial.row + self.initial_column = self.initial.column + #print(self.initial) + #random move + self.value = random.randrange(0, len(self.initial.piece.valid_moves)) + self.final = self.initial.piece.valid_moves[self.value] + self.final_row = self.final[0] + self.final_column = self.final[1] + #print(self.final) + #print(self.final_row) + #update + self.x = self.board.boardlist[self.initial_row][self.initial_column].piece + #print(self.board.boardlist[self.initial_row][self.initial_column].piece.name) + #print(self.initial_row, self.initial_column) + self.board.boardlist[self.initial_row][self.initial_column].piece = None + #print(self.final_row, self.final_column) + if (self.board.boardlist[self.final_row][self.final_column].has_piece()): + if (self.board.boardlist[self.final_row][self.final_column].piece.name== 'king'): + self.board.boardlist[self.final_row][self.final_column].piece = self.x + return 1 + self.board.boardlist[self.final_row][self.final_column].piece = self.x + self.board.boardlist[self.final_row][self.final_column].piece.moved = True + self.board.boardlist[self.final_row][self.final_column].piece.delete_moves() + #print(self.board.boardlist[self.final_row][self.final_column].piece.name) + #print(self.initial_row, self.initial_column) + #print(self.final_row, self.final_column) + return 0 + + + + diff --git a/game.py b/game.py new file mode 100644 index 0000000..f96fceb --- /dev/null +++ b/game.py @@ -0,0 +1,91 @@ +from board import Board +import random + +class Game: + def __init__(self): + self.board = Board() + + def show_board(self): + self.b = [] + for row in range(8): + if row==0: self.b.append('0') + if row == 1: self.b.append('1') + if row==2: self.b.append('2') + if row == 3: self.b.append('3') + if row==4: self.b.append('4') + if row == 5: self.b.append('5') + if row==6: self.b.append('6') + if row == 7: self.b.append('7') + for column in range(8): + if self.board.boardlist[row][column].has_piece(): + self.piece = self.board.boardlist[row][column].piece.name + self.color=self.board.boardlist[row][column].piece.color + if self.piece == 'rook': + if self.color=='white': + self.b.append('r') + else: self.b.append('R') + self.board.calc_moves(self.board.boardlist[row][column].piece, row, column) + elif self.piece == 'pawn': + if self.color=='white': + self.b.append('p') + else: + self.b.append('P') + self.board.calc_moves(self.board.boardlist[row][column].piece, row, column) + elif self.piece == 'knight': + if self.color=='white': + self.b.append('h') + else: + self.b.append('H') + self.board.calc_moves(self.board.boardlist[row][column].piece, row, column) + elif self.piece == 'bishop': + if self.color=='white': + self.b.append('b') + else: + self.b.append('B') + self.board.calc_moves(self.board.boardlist[row][column].piece, row, column) + elif self.piece == 'queen': + if self.color=='white': + self.b.append('q') + else: + self.b.append('Q') + self.board.calc_moves(self.board.boardlist[row][column].piece, row, column) + elif self.piece == 'king': + if self.color=='white': + self.b.append('k') + else: + self.b.append('K') + self.board.calc_moves(self.board.boardlist[row][column].piece, row, column) + else: + # wyswietla puste miejsca + self.b.append(' ') + print(self.b) + self.b = [] + self.b.append(' ') + self.b.append('0') + self.b.append('1') + self.b.append('2') + self.b.append('3') + self.b.append('4') + self.b.append('5') + self.b.append('6') + self.b.append('7') + print(self.b) + # sprawdzenie + # H + # self.board.calc_moves(self.board.boardlist[7][6].piece, 7, 6) + # print(self.board.boardlist[7][6].piece.valid_moves) + # P + # print(self.board.boardlist[6][0].piece.valid_moves) + # R + #print(self.board.boardlist[5][1].piece.color) + #print(self.board.boardlist[5][1].piece.valid_moves) + def make_move_rival(self): + self.przeciwnik = input(str('Podaj ruch: ')) + self.from_row = int(self.przeciwnik[0]) + self.from_column = int(self.przeciwnik[1]) + self.to_row = int(self.przeciwnik[3]) + self.to_column = int(self.przeciwnik[4]) + return Board.move_rival(self, self.from_row, self.from_column, self.to_row, self.to_column) + def make_move_boot(self, color): + return Board.move_boot(self, color) + diff --git a/king.py b/king.py new file mode 100644 index 0000000..a9c3a8c --- /dev/null +++ b/king.py @@ -0,0 +1,5 @@ +from piece import Piece + +class King(Piece): + def __init__(self, color): + super().__init__("king", color) \ No newline at end of file diff --git a/knight.py b/knight.py new file mode 100644 index 0000000..537ceea --- /dev/null +++ b/knight.py @@ -0,0 +1,5 @@ +from piece import Piece +from square import Square +class Knight(Piece): + def __init__(self, color): + super().__init__("knight", color) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..30f14ad --- /dev/null +++ b/main.py @@ -0,0 +1,28 @@ +from game import Game +#def mainloop(self): +# game = self.game +game = Game() +game.show_board() +boot_color = 'white' +#11 21 +a=0 +while True: + a = a + 1 + print(a) + if game.make_move_boot('white') == 1: + print("Przegrana") + game.show_board() + break + #if game.make_move_rival()==1: + # print("Przegrana") + # break + game.show_board() + print('') + if game.make_move_boot('black') == 1: + print("Przegrana") + game.show_board() + break + game.show_board() + print('') + + diff --git a/pawn.py b/pawn.py new file mode 100644 index 0000000..9a889c5 --- /dev/null +++ b/pawn.py @@ -0,0 +1,5 @@ +from piece import Piece + +class Pawn(Piece): + def __init__(self, color): + super().__init__("pawn", color) \ No newline at end of file diff --git a/piece.py b/piece.py new file mode 100644 index 0000000..7dd6a5d --- /dev/null +++ b/piece.py @@ -0,0 +1,18 @@ +class Piece: + def __init__(self, name, color): + self.name = name + self.color = color + self.valid_moves = [] + self.moved = False + + # kierunek pionkow, czarne w górę, białe w dół + if color == 'white': + self.pawn_direction = -1 + else: + self.pawn_direction = 1 + + def add_moves(self, move): + self.valid_moves.append(move) + + def delete_moves(self): + self.valid_moves = [] diff --git a/queen.py b/queen.py new file mode 100644 index 0000000..4692fbb --- /dev/null +++ b/queen.py @@ -0,0 +1,5 @@ +from piece import Piece + +class Queen(Piece): + def __init__(self, color): + super().__init__("queen", color) \ No newline at end of file diff --git a/rook.py b/rook.py new file mode 100644 index 0000000..30c9c4d --- /dev/null +++ b/rook.py @@ -0,0 +1,5 @@ +from piece import Piece + +class Rook(Piece): + def __init__(self, color): + super().__init__("rook", color) \ No newline at end of file diff --git a/square.py b/square.py new file mode 100644 index 0000000..68d56be --- /dev/null +++ b/square.py @@ -0,0 +1,34 @@ +class Square: + # tworzenie pól + def __init__(self, row, column, piece=None): + self.row = row + self.column = column + self.piece = piece + + def has_piece(self): + if self.piece is None: + return False + else: + return True + + def is_rival(self, color): + if self.has_piece() is True and self.piece.color != color: + return True + + def empty_or_rival(self, color): # sprawdz + if self.has_piece() is False or self.is_rival(color): # 1 has piece (color) + return True + else: + return False + def empty_or_rival_knight(self, color): # sprawdz + if self.has_piece() is False or self.is_rival(color): # 1 has piece (color) + return True + else: + return False + + @staticmethod + def on_board(*args): + for arg in args: + if arg < 0 or arg > 7: + return False + return True