brewersfan1976

bishop_and_pawn.rb

Jan 7th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.52 KB | None | 0 0
  1. def bishopAndPawn(bishop, pawn)
  2.     if bishop[0] == 'a' then
  3.        bishop_first_value = 1
  4.     end
  5.        
  6.     if bishop[0] == 'b' then
  7.        bishop_first_value = 2
  8.     end
  9.        
  10.     if bishop[0] == 'c' then
  11.        bishop_first_value = 3
  12.     end
  13.        
  14.     if bishop[0] == 'd' then
  15.        bishop_first_value = 4
  16.     end
  17.        
  18.     if bishop[0] == 'e' then
  19.        bishop_first_value = 5
  20.     end
  21.        
  22.     if bishop[0] == 'f' then
  23.        bishop_first_value = 6
  24.     end
  25.        
  26.     if bishop[0] == 'g' then
  27.        bishop_first_value = 7
  28.     end
  29.        
  30.     if bishop[0] == 'h' then
  31.        bishop_first_value = 8
  32.     end
  33.        
  34.     bishop_second_value = bishop[1].to_i
  35.        
  36.     if pawn[0] == 'a' then
  37.        pawn_first_value = 1
  38.     end
  39.        
  40.     if pawn[0] == 'b' then
  41.        pawn_first_value = 2
  42.     end
  43.        
  44.     if pawn[0] == 'c' then
  45.        pawn_first_value = 3
  46.     end
  47.        
  48.     if pawn[0] == 'd' then
  49.        pawn_first_value = 4
  50.     end
  51.        
  52.     if pawn[0] == 'e' then
  53.        pawn_first_value = 5
  54.     end
  55.        
  56.     if pawn[0] == 'f' then
  57.        pawn_first_value = 6
  58.     end
  59.        
  60.     if pawn[0] == 'g' then
  61.        pawn_first_value = 7
  62.     end
  63.        
  64.     if pawn[0] == 'h' then
  65.        pawn_first_value = 8
  66.     end
  67.        
  68.     pawn_second_value = pawn[1].to_i
  69.        
  70.     if (bishop_first_value - pawn_first_value).abs == (bishop_second_value - pawn_second_value).abs then
  71.         return true
  72.     else
  73.         return false
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment