Advertisement
Guest User

APPLICATION

a guest
Nov 14th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 1.88 KB | None | 0 0
  1. note
  2.     description: "Summary description for {PIECE}."
  3.     author: ""
  4.     date: "$Date$"
  5.     revision: "$Revision$"
  6.  
  7. class
  8.     PIECE
  9.  
  10. create
  11.     make
  12.  
  13. feature
  14.     color: BOOLEAN
  15.     position_x: INTEGER
  16.     position_y: INTEGER
  17.     type:STRING
  18.     first_move: BOOLEAN
  19.  
  20.     make(t:STRING; clr:BOOLEAN; x,y:INTEGER)
  21.     do
  22.         type:=  t
  23.         color:= clr
  24.         position_x:= x
  25.         position_y:= y
  26.         first_move:= true
  27.     end
  28.  
  29.     feature
  30.  
  31.     set_newPos(x,y: INTEGER)
  32.     do
  33.         position_x:= x
  34.         position_y:= y
  35.     end
  36.  
  37.     can_move(x,y: INTEGER):BOOLEAN
  38.     do
  39.         if (type ~ "pawn") then
  40.             if ((color = true and (y - position_y) = 1) or (color = false and (y - position_y) = -1)) then
  41.                 RESULT:= true;
  42.             else
  43.                 RESULT:= false;
  44.             end
  45.  
  46.         elseif (type ~ "bishop") then
  47.                 if ((y - position_y).abs = (x - position_x).abs) then
  48.                     RESULT:= true;
  49.                 else
  50.                     RESULT:= false;
  51.                 end
  52.  
  53.         elseif (type ~ "knight") then
  54.                 if (((y - position_y).abs = 2 and (x - position_x).abs = 1) or ((y - position_y).abs = 1 and (x - position_x).abs = 2)) then
  55.                     RESULT:= true;
  56.                 else
  57.                     RESULT:= false;
  58.                 end
  59.  
  60.         elseif (type ~ "rook") then
  61.                 if (((y - position_y).abs /= 0 and (x - position_x).abs = 0) or ((y - position_y).abs = 0 and (x - position_x).abs /= 0)) then
  62.                     RESULT:= true;
  63.                 else
  64.                     RESULT:= false;
  65.                 end
  66.  
  67.         elseif (type ~ "queen") then
  68.                 if (((y - position_y).abs /= 0 and (x - position_x).abs = 0) or ((y - position_y).abs = 0 and (x - position_x).abs /= 0)
  69.                     or (y - position_y).abs = (x - position_x).abs)
  70.                     then
  71.  
  72.                     RESULT:= true;
  73.                 else
  74.                     RESULT:= false;
  75.                 end
  76.  
  77.         elseif (type ~ "king") then
  78.                 if (((x-position_x).abs = 1 and (y-position_y).abs = 0)
  79.                      or ((y-position_y).abs = 1 and (x-position_x).abs = 0)
  80.                      or ((x-position_x).abs = 1 and (y-position_y).abs = 1))
  81.                      then
  82.  
  83.                     RESULT:= true;
  84.                 else
  85.                     RESULT:= false;
  86.                 end
  87.         end
  88.     end
  89.  
  90.  
  91.  
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement