{"id":331741,"date":"2022-04-09T21:00:15","date_gmt":"2022-04-09T21:00:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=331741"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=331741","title":{"rendered":"<span>\u0414\u0438\u0437\u0430\u0439\u043d \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0438\u0433\u0440\u044b<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/345\/728\/dd0\/345728dd03fb9fc4e30eb4cde0f2fc42.jpg\" alt=\"\u0440\u0438\u0441 1.\" title=\"\u0440\u0438\u0441 1.\" width=\"1200\" height=\"630\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/345\/728\/dd0\/345728dd03fb9fc4e30eb4cde0f2fc42.jpg\" data-blurred=\"true\"\/><figcaption>\u0440\u0438\u0441 1.<\/figcaption><\/figure>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0441 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0435\u0439<\/p>\n<p><strong>\u0410\u0432\u0442\u043e\u0440 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430:<\/strong><br \/> shashipk11<br \/> <span>@shashipk11<\/span><br \/> <a href=\"https:\/\/auth.geeksforgeeks.org\/user\/shashipk11\/articles\" rel=\"noopener noreferrer nofollow\">https:\/\/auth.geeksforgeeks.org\/user\/shashipk11\/articles<\/a><\/p>\n<p><strong>\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b:<\/strong><br \/> <a href=\"https:\/\/www.geeksforgeeks.org\/design-a-chess-game\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.geeksforgeeks.org\/design-a-chess-game\/<\/a><br \/> <a href=\"https:\/\/massivetechinterview.blogspot.com\/2015\/07\/design-chess-game-using-oo-principles.html\" rel=\"noopener noreferrer nofollow\">https:\/\/massivetechinterview.blogspot.com\/2015\/07\/design-chess-game-using-oo-principles.html<\/a><\/p>\n<p><strong>\u0423\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438:<\/strong> \u0421\u043b\u043e\u0436\u043d\u044b\u0439<br \/><strong>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435:<\/strong> 30 \u0421\u0435\u043d\u0442., 2020<\/p>\n<p><strong>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438:<\/strong><br \/> \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u0443\u044e \u0438\u0433\u0440\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432.<\/p>\n<p><strong>\u041d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441:<\/strong> Adobe, Amazon, Microsoft \u0438 \u0442. \u0434.<\/p>\n<p><strong>\u0420\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong><br \/>\u042d\u0442\u0438 \u0432\u0438\u0434\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0432\u044c\u044e, \u0447\u0442\u043e\u0431\u044b \u0441\u0443\u0434\u0438\u0442\u044c \u043e \u043d\u0430\u0432\u044b\u043a\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430. \u0418\u0442\u0430\u043a, \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043e \u043a\u043b\u0430\u0441\u0441\u0430\u0445.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430<em>:<\/em> <br \/> \u0425\u043e\u0440\u043e\u0448\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u043a\u043e\u0434\u0430 \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c UML \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443.<br \/> \u0417\u0430\u0442\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0432 \u0441\u0432\u044f\u0437\u0438 \u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f, \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0431\u044b\u043b \u0431\u044b \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u044b\u043c \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u043e\u0442\u043d\u0438\u043c\u0430\u043b\u043e \u0431\u044b \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p><em>\u0414\u0430\u043b\u0435\u0435 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435:<\/em> <strong>\u041f\u0440\u0438\u043c.<\/strong> &#8212; \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430.<\/p>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0431\u0443\u0434\u0443\u0442:<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043b\u0435\u0442\u043a\u0430(\u043a\u043b\u0430\u0441\u0441 Spot):<\/strong> \u041a\u043b\u0435\u0442\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0434\u0438\u043d \u0431\u043b\u043e\u043a \u0441\u0435\u0442\u043a\u0438 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0438\u0433\u0443\u0440\u0430 (\u043a\u043b\u0430\u0441\u0441 Piece)<\/strong> &#8212; \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0431\u043b\u043e\u043a \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<br \/> \u041a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0444\u0438\u0433\u0443\u0440\u0430, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Piece, \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043d\u0430  \u043a\u043b\u0435\u0442\u043a\u0435. \u0424\u0438\u0433\u0443\u0440\u0430 (\u043a\u043b\u0430\u0441\u0441 Piece) \u0431\u0443\u0434\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. \u041a\u043b\u0430\u0441\u0441\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438 (\u041f\u0435\u0448\u043a\u0430(\u043a\u043b\u0430\u0441\u0441 Pawn),\u041a\u043e\u043d\u044c (\u043a\u043b\u0430\u0441\u0441 King), \u0424\u0435\u0440\u0437\u044c (\u043a\u043b\u0430\u0441\u0441 Queen), \u041b\u0430\u0434\u044c\u044f (\u043a\u043b\u0430\u0441\u0441 Rook), \u041a\u043e\u0440\u043e\u043b\u044c (\u043a\u043b\u0430\u0441\u0441 Knight), \u0421\u043b\u043e\u043d \u0438\u043b\u0438 \u043e\u0444\u0438\u0446\u0435\u0440(\u043a\u043b\u0430\u0441\u0441 Bishop) )  \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430: \u0441\u043b\u043e\u0432\u043e &#8212; &#171;Bishop&#187; \u043c\u043e\u0436\u0435\u0442 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u043e \u043a\u0430\u043a \u043e\u0444\u0438\u0446\u0435\u0440. \u0418\u043c\u0435\u044e\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u044b\u0435 \u0444\u0438\u0433\u0443\u0440\u044b, \u0438 &#171;\u0415\u043f\u0438\u0441\u043a\u043e\u043f\u043e\u043c&#187; \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u0443\u044e \u0444\u0438\u0433\u0443\u0440\u0443 \u043d\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442.<\/p>\n<ul>\n<li>\n<p><strong>\u0414\u043e\u0441\u043a\u0430(\u043a\u043b\u0430\u0441\u0441 Board):<\/strong> \u043d\u0430\u0431\u043e\u0440 \u043a\u043b\u0435\u0442\u043e\u043a 8\u04458.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0433\u0440\u043e\u043a(\u043a\u043b\u0430\u0441\u0441 Player)<\/strong> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435 (\u043a\u043b\u0430\u0441\u0441 Move):<\/strong> \u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435(\u0445\u043e\u0434) \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0445\u043e\u0434 \u0432 \u0438\u0433\u0440\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0443\u044e \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443. \u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0440\u044d\u043a \u0438\u0433\u0440\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 \u0445\u043e\u0434\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0433\u0440\u0430 (\u043a\u043b\u0430\u0441\u0441 Game):<\/strong> \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0438\u0433\u0440\u044b.<br \/> \u041e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u0443\u0442\u044c \u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u0432\u0441\u0435\u0445 \u0445\u043e\u0434\u043e\u0432 \u0438\u0433\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0434\u0435\u043b\u0430\u043b \u0438\u0433\u0440\u043e\u043a,  \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0434\u0435\u0442\u0430\u043b\u0438. \u041a\u043e\u0434 \u044f\u0441\u043d\u044b\u0439 \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0441\u0430\u043c \u0437\u0430 \u0441\u0435\u0431\u044f. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438(\u043a\u043b\u0435\u0442\u043a\u0438) \u043d\u0430 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0435:<\/p>\n<pre><code class=\"java\">public class Spot {     private Piece piece;     private int x;     private int y;        public Spot(int x, int y, Piece piece)     {         this.setPiece(piece);         this.setX(x);         this.setY(y);     }         public Piece getPiece() \/\/ \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0444\u0438\u0433\u0443\u0440\u0443     {         return this.piece;     }        public void setPiece(Piece p)     {         this.piece = p;     }        public int getX()     {         return this.x;     }        public void setX(int x)     {         this.x = x;     }        public int getY()     {         return this.y;     }        public void setY(int y)     {         this.y = y;     } }<\/code><\/pre>\n<p>\u0424\u0438\u0433\u0443\u0440\u0430(\u043a\u043b\u0430\u0441\u0441 Piece): \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0435\u0445 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u044b\u0445 \u0444\u0438\u0433\u0443\u0440:<\/p>\n<pre><code class=\"java\">public abstract class Piece {        private boolean killed = false;     private boolean white = false;        public Piece(boolean white)     {         this.setWhite(white);     }        public boolean isWhite()     {         return this.white;     }        public void setWhite(boolean white)     {         this.white = white;     }        public boolean isKilled()     {         return this.killed;     }        public void setKilled(boolean killed)     {         this.killed = killed;     }        public abstract boolean canMove(Board board,                                   Spot start, Spot end); } <\/code><\/pre>\n<p>\u041a\u043e\u0440\u043e\u043b\u044c(\u043a\u043b\u0430\u0441\u0441 Knight): \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u0443\u044e \u0444\u0438\u0433\u0443\u0440\u0443 &#8212;  \u043a\u043e\u0440\u043e\u043b\u044f:<\/p>\n<pre><code>public class Knight extends Piece {     public Knight(boolean white)     {         super(white);     }        @Override     public boolean canMove(Board board, Spot start,                                              Spot end)     {         \/\/ we can't move the piece to a spot that has         \/\/ a piece of the same colour         if (end.getPiece().isWhite() == this.isWhite()) {             return false;         }            int x = Math.abs(start.getX() - end.getX());         int y = Math.abs(start.getY() - end.getY());         return x * y == 2;     } }<\/code><\/pre>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0438\u0433\u0443\u0440, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0444\u0435\u0440\u0437\u044c, \u043f\u0435\u0448\u043a\u0438, \u043b\u0430\u0434\u044c\u0438, \u0441\u043b\u043e\u043d\u0430 \u0438 \u0442. \u0434.<\/p>\n<p>\u0414\u043e\u0441\u043a\u0430(\u043a\u043b\u0430\u0441\u0441 Board): \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0438:<\/p>\n<pre><code>public class Board {     Spot[][] boxes;        public Board()     {         this.resetBoard();     }        public Spot getBox(int x, int y)     {            if (x &lt; 0 || x > 7 || y &lt; 0 || y > 7) {             throw new Exception(\"Index out of bound\");         }            return boxes[x][y];     }        public void resetBoard()     {         \/\/ initialize white pieces         boxes[0][0] = new Spot(0, 0, new Rook(true));         boxes[0][1] = new Spot(0, 1, new Knight(true));         boxes[0][2] = new Spot(0, 2, new Bishop(true));         \/\/...         boxes[1][0] = new Spot(1, 0, new Pawn(true));         boxes[1][1] = new Spot(1, 1, new Pawn(true));         \/\/...            \/\/ initialize black pieces         boxes[7][0] = new Spot(7, 0, new Rook(false));         boxes[7][1] = new Spot(7, 1, new Knight(false));         boxes[7][2] = new Spot(7, 2, new Bishop(false));         \/\/...         boxes[6][0] = new Spot(6, 0, new Pawn(false));         boxes[6][1] = new Spot(6, 1, new Pawn(false));         \/\/...            \/\/ initialize remaining boxes without any piece         for (int i = 2; i &lt; 6; i++) {             for (int j = 0; j &lt; 8; j++) {                 boxes[i][j] = new Spot(i, j, null);             }         }     } }<\/code><\/pre>\n<p><em>\u041f\u0440\u0438\u043c.<\/em><\/p>\n<pre><code class=\"java\">public Spot getBox(int x, int y) throws Exception {      if (x &lt; 0 || x > 7 || y &lt; 0 || y > 7) {         throw new Exception(\"Index out of bound\");     }<\/code><\/pre>\n<p>\u0418\u0433\u0440\u043e\u043a(\u043a\u043b\u0430\u0441\u0441 Player): \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u0433\u0440\u043e\u043a. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0437 \u0441\u0435\u0431\u044f  \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0438\u043b\u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440.<\/p>\n<p><em>\u041f\u0440\u0438\u043c.<\/em> \u0412 \u0442\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435, \u0447\u0442\u043e \u0438\u0433\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c: \u0427\u0435\u043b\u043e\u0432\u0435\u043a-\u0427\u0435\u043b\u043e\u0432\u0435\u043a, \u041a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440-\u041a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440,<br \/> \u0427\u0435\u043b\u043e\u0432\u0435\u043a-\u041a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440.<\/p>\n<pre><code>public abstract class Player {     public boolean whiteSide;     public boolean humanPlayer;        public boolean isWhiteSide()     {         return this.whiteSide;     }     public boolean isHumanPlayer()     {         return this.humanPlayer;     } }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441: HumanPlayer<\/p>\n<pre><code class=\"java\">public class HumanPlayer extends Player {        public HumanPlayer(boolean whiteSide)     {         this.whiteSide = whiteSide;         this.humanPlayer = true;     } }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441: ComputerPlayer<\/p>\n<pre><code>public class ComputerPlayer extends Player {        public ComputerPlayer(boolean whiteSide)     {         this.whiteSide = whiteSide;         this.humanPlayer = false;     } }<\/code><\/pre>\n<p>\u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435(\u043a\u043b\u0430\u0441\u0441 Move): \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f(\u0445\u043e\u0434\u0430).<\/p>\n<pre><code class=\"java\">public class Move {     private Player player;     private Spot start;     private Spot end;     private Piece pieceMoved;     private Piece pieceKilled;     private boolean castlingMove = false;        public Move(Player player, Spot start, Spot end)     {         this.player = player;         this.start = start;         this.end = end;         this.pieceMoved = start.getPiece();     }        public boolean isCastlingMove()     {         return this.castlingMove;     }        public void setCastlingMove(boolean castlingMove)     {         this.castlingMove = castlingMove;     } }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435: \u0421\u0442\u0430\u0442\u0443\u0441 \u0438\u0433\u0440\u044b<\/p>\n<pre><code class=\"java\">public enum GameStatus {     ACTIVE,     BLACK_WIN,     WHITE_WIN,     FORFEIT,     STALEMATE,     RESIGNATION }<\/code><\/pre>\n<p>\u0418\u0433\u0440\u0430(\u043a\u043b\u0430\u0441\u0441 Game): \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u044b \u0432 \u0448\u0430\u0445\u043c\u0430\u0442\u044b:<\/p>\n<pre><code>public class Game {     private Player[] players;     private Board board;     private Player currentTurn;     private GameStatus status;     private List&lt;Move> movesPlayed;        private void initialize(Player p1, Player p2)     {         players[0] = p1;         players[1] = p2;            board.resetBoard();            if (p1.isWhiteSide()) {             this.currentTurn = p1;         }         else {             this.currentTurn = p2;         }            movesPlayed.clear();     }        public boolean isEnd()     {         return this.getStatus() != GameStatus.ACTIVE;     }        public boolean getStatus()     {         return this.status;     }        public void setStatus(GameStatus status)     {         this.status = status;     }        public boolean playerMove(Player player, int startX,                                  int startY, int endX, int endY)     {         Spot startBox = board.getBox(startX, startY);         Spot endBox = board.getBox(startY, endY);         Move move = new Move(player, startBox, endBox);         return this.makeMove(move, player);     }        private boolean makeMove(Move move, Player player)     {         Piece sourcePiece = move.getStart().getPiece();         if (sourcePiece == null) {             return false;         }            \/\/ valid player         if (player != currentTurn) {             return false;         }            if (sourcePiece.isWhite() != player.isWhiteSide()) {             return false;         }            \/\/ valid move?         if (!sourcePiece.canMove(board, move.getStart(),                                              move.getEnd())) {             return false;         }            \/\/ kill?         Piece destPiece = move.getStart().getPiece();         if (destPiece != null) {             destPiece.setKilled(true);             move.setPieceKilled(destPiece);         }            \/\/ castling?         if (sourcePiece != null &amp;&amp; sourcePiece instanceof King             &amp;&amp; sourcePiece.isCastlingMove()) {             move.setCastlingMove(true);         }            \/\/ store the move         movesPlayed.add(move);            \/\/ move piece from the stat box to end box         move.getEnd().setPiece(move.getStart().getPiece());         move.getStart.setPiece(null);            if (destPiece != null &amp;&amp; destPiece instanceof King) {             if (player.isWhiteSide()) {                 this.setStatus(GameStatus.WHITE_WIN);             }             else {                 this.setStatus(GameStatus.BLACK_WIN);             }         }            \/\/ set the current turn to the other player         if (this.currentTurn == players[0]) {             this.currentTurn = players[1];         }         else {             this.currentTurn = players[0];         }            return true;     } }<\/code><\/pre>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u0411\u0443\u0434\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 &#8212; \u0441\u0434\u0435\u043b\u0430\u044e \u0440\u0435\u0432\u044c\u044e \u043a\u043e\u0434\u0430.<br \/>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0435 \u044f \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u043a\u043e\u0434 \u043a\u0430\u043a \u0435\u0441\u0442\u044c, \u043a\u0430\u043a \u043e\u043d \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/660003\/\"> https:\/\/habr.com\/ru\/post\/660003\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption>\u0440\u0438\u0441 1.<\/figcaption><\/figure>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0441 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0435\u0439<\/p>\n<p><strong>\u0410\u0432\u0442\u043e\u0440 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430:<\/strong><br \/> shashipk11<br \/> <span>@shashipk11<\/span><br \/> <a href=\"https:\/\/auth.geeksforgeeks.org\/user\/shashipk11\/articles\" rel=\"noopener noreferrer nofollow\">https:\/\/auth.geeksforgeeks.org\/user\/shashipk11\/articles<\/a><\/p>\n<p><strong>\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b:<\/strong><br \/> <a href=\"https:\/\/www.geeksforgeeks.org\/design-a-chess-game\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.geeksforgeeks.org\/design-a-chess-game\/<\/a><br \/> <a href=\"https:\/\/massivetechinterview.blogspot.com\/2015\/07\/design-chess-game-using-oo-principles.html\" rel=\"noopener noreferrer nofollow\">https:\/\/massivetechinterview.blogspot.com\/2015\/07\/design-chess-game-using-oo-principles.html<\/a><\/p>\n<p><strong>\u0423\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438:<\/strong> \u0421\u043b\u043e\u0436\u043d\u044b\u0439<br \/><strong>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435:<\/strong> 30 \u0421\u0435\u043d\u0442., 2020<\/p>\n<p><strong>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438:<\/strong><br \/> \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u0443\u044e \u0438\u0433\u0440\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432.<\/p>\n<p><strong>\u041d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441:<\/strong> Adobe, Amazon, Microsoft \u0438 \u0442. \u0434.<\/p>\n<p><strong>\u0420\u0435\u0448\u0435\u043d\u0438\u0435:<\/strong><br \/>\u042d\u0442\u0438 \u0432\u0438\u0434\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0432\u044c\u044e, \u0447\u0442\u043e\u0431\u044b \u0441\u0443\u0434\u0438\u0442\u044c \u043e \u043d\u0430\u0432\u044b\u043a\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430. \u0418\u0442\u0430\u043a, \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043e \u043a\u043b\u0430\u0441\u0441\u0430\u0445.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430<em>:<\/em> <br \/> \u0425\u043e\u0440\u043e\u0448\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u043a\u043e\u0434\u0430 \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c UML \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443.<br \/> \u0417\u0430\u0442\u0435\u043c \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0432 \u0441\u0432\u044f\u0437\u0438 \u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f, \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0431\u044b\u043b \u0431\u044b \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u044b\u043c \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u043e\u0442\u043d\u0438\u043c\u0430\u043b\u043e \u0431\u044b \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p><em>\u0414\u0430\u043b\u0435\u0435 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435:<\/em> <strong>\u041f\u0440\u0438\u043c.<\/strong> &#8212; \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430.<\/p>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0431\u0443\u0434\u0443\u0442:<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043b\u0435\u0442\u043a\u0430(\u043a\u043b\u0430\u0441\u0441 Spot):<\/strong> \u041a\u043b\u0435\u0442\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0434\u0438\u043d \u0431\u043b\u043e\u043a \u0441\u0435\u0442\u043a\u0438 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0438\u0433\u0443\u0440\u0430 (\u043a\u043b\u0430\u0441\u0441 Piece)<\/strong> &#8212; \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0431\u043b\u043e\u043a \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<br \/> \u041a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0444\u0438\u0433\u0443\u0440\u0430, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Piece, \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043d\u0430  \u043a\u043b\u0435\u0442\u043a\u0435. \u0424\u0438\u0433\u0443\u0440\u0430 (\u043a\u043b\u0430\u0441\u0441 Piece) \u0431\u0443\u0434\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. \u041a\u043b\u0430\u0441\u0441\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438 (\u041f\u0435\u0448\u043a\u0430(\u043a\u043b\u0430\u0441\u0441 Pawn),\u041a\u043e\u043d\u044c (\u043a\u043b\u0430\u0441\u0441 King), \u0424\u0435\u0440\u0437\u044c (\u043a\u043b\u0430\u0441\u0441 Queen), \u041b\u0430\u0434\u044c\u044f (\u043a\u043b\u0430\u0441\u0441 Rook), \u041a\u043e\u0440\u043e\u043b\u044c (\u043a\u043b\u0430\u0441\u0441 Knight), \u0421\u043b\u043e\u043d \u0438\u043b\u0438 \u043e\u0444\u0438\u0446\u0435\u0440(\u043a\u043b\u0430\u0441\u0441 Bishop) )  \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430: \u0441\u043b\u043e\u0432\u043e &#8212; &#171;Bishop&#187; \u043c\u043e\u0436\u0435\u0442 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u043e \u043a\u0430\u043a \u043e\u0444\u0438\u0446\u0435\u0440. \u0418\u043c\u0435\u044e\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u044b\u0435 \u0444\u0438\u0433\u0443\u0440\u044b, \u0438 &#171;\u0415\u043f\u0438\u0441\u043a\u043e\u043f\u043e\u043c&#187; \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u0443\u044e \u0444\u0438\u0433\u0443\u0440\u0443 \u043d\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442.<\/p>\n<ul>\n<li>\n<p><strong>\u0414\u043e\u0441\u043a\u0430(\u043a\u043b\u0430\u0441\u0441 Board):<\/strong> \u043d\u0430\u0431\u043e\u0440 \u043a\u043b\u0435\u0442\u043e\u043a 8\u04458.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0433\u0440\u043e\u043a(\u043a\u043b\u0430\u0441\u0441 Player)<\/strong> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435 (\u043a\u043b\u0430\u0441\u0441 Move):<\/strong> \u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435(\u0445\u043e\u0434) \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0445\u043e\u0434 \u0432 \u0438\u0433\u0440\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0443\u044e \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443. \u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0440\u044d\u043a \u0438\u0433\u0440\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 \u0445\u043e\u0434\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0433\u0440\u0430 (\u043a\u043b\u0430\u0441\u0441 Game):<\/strong> \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0438\u0433\u0440\u044b.<br \/> \u041e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u0443\u0442\u044c \u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u0432\u0441\u0435\u0445 \u0445\u043e\u0434\u043e\u0432 \u0438\u0433\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0434\u0435\u043b\u0430\u043b \u0438\u0433\u0440\u043e\u043a,  \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0434\u0435\u0442\u0430\u043b\u0438. \u041a\u043e\u0434 \u044f\u0441\u043d\u044b\u0439 \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0441\u0430\u043c \u0437\u0430 \u0441\u0435\u0431\u044f. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438(\u043a\u043b\u0435\u0442\u043a\u0438) \u043d\u0430 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0435:<\/p>\n<pre><code class=\"java\">public class Spot {     private Piece piece;     private int x;     private int y;        public Spot(int x, int y, Piece piece)     {         this.setPiece(piece);         this.setX(x);         this.setY(y);     }         public Piece getPiece() \/\/ \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0444\u0438\u0433\u0443\u0440\u0443     {         return this.piece;     }        public void setPiece(Piece p)     {         this.piece = p;     }        public int getX()     {         return this.x;     }        public void setX(int x)     {         this.x = x;     }        public int getY()     {         return this.y;     }        public void setY(int y)     {         this.y = y;     } }<\/code><\/pre>\n<p>\u0424\u0438\u0433\u0443\u0440\u0430(\u043a\u043b\u0430\u0441\u0441 Piece): \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0435\u0445 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u044b\u0445 \u0444\u0438\u0433\u0443\u0440:<\/p>\n<pre><code class=\"java\">public abstract class Piece {        private boolean killed = false;     private boolean white = false;        public Piece(boolean white)     {         this.setWhite(white);     }        public boolean isWhite()     {         return this.white;     }        public void setWhite(boolean white)     {         this.white = white;     }        public boolean isKilled()     {         return this.killed;     }        public void setKilled(boolean killed)     {         this.killed = killed;     }        public abstract boolean canMove(Board board,                                   Spot start, Spot end); } <\/code><\/pre>\n<p>\u041a\u043e\u0440\u043e\u043b\u044c(\u043a\u043b\u0430\u0441\u0441 Knight): \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u0443\u044e \u0444\u0438\u0433\u0443\u0440\u0443 &#8212;  \u043a\u043e\u0440\u043e\u043b\u044f:<\/p>\n<pre><code>public class Knight extends Piece {     public Knight(boolean white)     {         super(white);     }        @Override     public boolean canMove(Board board, Spot start,                                              Spot end)     {         \/\/ we can't move the piece to a spot that has         \/\/ a piece of the same colour         if (end.getPiece().isWhite() == this.isWhite()) {             return false;         }            int x = Math.abs(start.getX() - end.getX());         int y = Math.abs(start.getY() - end.getY());         return x * y == 2;     } }<\/code><\/pre>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0438\u0433\u0443\u0440, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0444\u0435\u0440\u0437\u044c, \u043f\u0435\u0448\u043a\u0438, \u043b\u0430\u0434\u044c\u0438, \u0441\u043b\u043e\u043d\u0430 \u0438 \u0442. \u0434.<\/p>\n<p>\u0414\u043e\u0441\u043a\u0430(\u043a\u043b\u0430\u0441\u0441 Board): \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0438:<\/p>\n<pre><code>public class Board {     Spot[][] boxes;        public Board()     {         this.resetBoard();     }        public Spot getBox(int x, int y)     {            if (x &lt; 0 || x > 7 || y &lt; 0 || y > 7) {             throw new Exception(\"Index out of bound\");         }            return boxes[x][y];     }        public void resetBoard()     {         \/\/ initialize white pieces         boxes[0][0] = new Spot(0, 0, new Rook(true));         boxes[0][1] = new Spot(0, 1, new Knight(true));         boxes[0][2] = new Spot(0, 2, new Bishop(true));         \/\/...         boxes[1][0] = new Spot(1, 0, new Pawn(true));         boxes[1][1] = new Spot(1, 1, new Pawn(true));         \/\/...            \/\/ initialize black pieces         boxes[7][0] = new Spot(7, 0, new Rook(false));         boxes[7][1] = new Spot(7, 1, new Knight(false));         boxes[7][2] = new Spot(7, 2, new Bishop(false));         \/\/...         boxes[6][0] = new Spot(6, 0, new Pawn(false));         boxes[6][1] = new Spot(6, 1, new Pawn(false));         \/\/...            \/\/ initialize remaining boxes without any piece         for (int i = 2; i &lt; 6; i++) {             for (int j = 0; j &lt; 8; j++) {                 boxes[i][j] = new Spot(i, j, null);             }         }     } }<\/code><\/pre>\n<p><em>\u041f\u0440\u0438\u043c.<\/em><\/p>\n<pre><code class=\"java\">public Spot getBox(int x, int y) throws Exception {      if (x &lt; 0 || x > 7 || y &lt; 0 || y > 7) {         throw new Exception(\"Index out of bound\");     }<\/code><\/pre>\n<p>\u0418\u0433\u0440\u043e\u043a(\u043a\u043b\u0430\u0441\u0441 Player): \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u0433\u0440\u043e\u043a. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0437 \u0441\u0435\u0431\u044f  \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0438\u043b\u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440.<\/p>\n<p><em>\u041f\u0440\u0438\u043c.<\/em> \u0412 \u0442\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435, \u0447\u0442\u043e \u0438\u0433\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c: \u0427\u0435\u043b\u043e\u0432\u0435\u043a-\u0427\u0435\u043b\u043e\u0432\u0435\u043a, \u041a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440-\u041a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440,<br \/> \u0427\u0435\u043b\u043e\u0432\u0435\u043a-\u041a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440.<\/p>\n<pre><code>public abstract class Player {     public boolean whiteSide;     public boolean humanPlayer;        public boolean isWhiteSide()     {         return this.whiteSide;     }     public boolean isHumanPlayer()     {         return this.humanPlayer;     } }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441: HumanPlayer<\/p>\n<pre><code class=\"java\">public class HumanPlayer extends Player {        public HumanPlayer(boolean whiteSide)     {         this.whiteSide = whiteSide;         this.humanPlayer = true;     } }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441: ComputerPlayer<\/p>\n<pre><code>public class ComputerPlayer extends Player {        public ComputerPlayer(boolean whiteSide)     {         this.whiteSide = whiteSide;         this.humanPlayer = false;     } }<\/code><\/pre>\n<p>\u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435(\u043a\u043b\u0430\u0441\u0441 Move): \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f(\u0445\u043e\u0434\u0430).<\/p>\n<pre><code class=\"java\">public class Move {     private Player player;     private Spot start;     private Spot end;     private Piece pieceMoved;     private Piece pieceKilled;     private boolean castlingMove = false;        public Move(Player player, Spot start, Spot end)     {         this.player = player;         this.start = start;         this.end = end;         this.pieceMoved = start.getPiece();     }        public boolean isCastlingMove()     {         return this.castlingMove;     }        public void setCastlingMove(boolean castlingMove)     {         this.castlingMove = castlingMove;     } }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435: \u0421\u0442\u0430\u0442\u0443\u0441 \u0438\u0433\u0440\u044b<\/p>\n<pre><code class=\"java\">public enum GameStatus {     ACTIVE,     BLACK_WIN,     WHITE_WIN,     FORFEIT,     STALEMATE,     RESIGNATION }<\/code><\/pre>\n<p>\u0418\u0433\u0440\u0430(\u043a\u043b\u0430\u0441\u0441 Game): \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u044b \u0432 \u0448\u0430\u0445\u043c\u0430\u0442\u044b:<\/p>\n<pre><code>public class Game {     private Player[] players;     private Board board;     private Player currentTurn;     private GameStatus status;     private List&lt;Move> movesPlayed;        private void initialize(Player p1, Player p2)     {         players[0] = p1;         players[1] = p2;            board.resetBoard();            if (p1.isWhiteSide()) {             this.currentTurn = p1;         }         else {             this.currentTurn = p2;         }            movesPlayed.clear();     }        public boolean isEnd()     {         return this.getStatus() != GameStatus.ACTIVE;     }        public boolean getStatus()     {         return this.status;     }        public void setStatus(GameStatus status)     {         this.status = status;     }        public boolean playerMove(Player player, int startX,                                  int startY, int endX, int endY)     {         Spot startBox = board.getBox(startX, startY);         Spot endBox = board.getBox(startY, endY);         Move move = new Move(player, startBox, endBox);         return this.makeMove(move, player);     }        private boolean makeMove(Move move, Player player)     {         Piece sourcePiece = move.getStart().getPiece();         if (sourcePiece == null) {             return false;         }            \/\/ valid player         if (player != currentTurn) {             return false;         }            if (sourcePiece.isWhite() != player.isWhiteSide()) {             return false;         }            \/\/ valid move?         if (!sourcePiece.canMove(board, move.getStart(),                                              move.getEnd())) {             return false;         }            \/\/ kill?         Piece destPiece = move.getStart().getPiece();         if (destPiece != null) {             destPiece.setKilled(true);             move.setPieceKilled(destPiece);         }            \/\/ castling?         if (sourcePiece != null &amp;&amp; sourcePiece instanceof King             &amp;&amp; sourcePiece.isCastlingMove()) {             move.setCastlingMove(true);         }            \/\/ store the move         movesPlayed.add(move);            \/\/ move piece from the stat box to end box         move.getEnd().setPiece(move.getStart().getPiece());         move.getStart.setPiece(null);            if (destPiece != null &amp;&amp; destPiece instanceof King) {             if (player.isWhiteSide()) {                 this.setStatus(GameStatus.WHITE_WIN);             }             else {                 this.setStatus(GameStatus.BLACK_WIN);             }         }         <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-331741","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=331741"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331741\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=331741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=331741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=331741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}