This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

chess960.rb

By: a guest on Dec 7th, 2012  |  syntax: Ruby  |  size: 0.72 KB  |  views: 63  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #960 chess position generator
  2. def assignment
  3.         positions = [1,3,5,7]
  4.         temppos = [2,4,6,8]
  5.  
  6.         assignments = {}
  7.  
  8.         positions.shuffle!
  9.         temppos.shuffle!
  10.  
  11.         assignments['B1'] = positions.pop
  12.         assignments['B2'] = temppos.pop
  13.  
  14.         positions = positions + temppos
  15.         positions.shuffle!
  16.  
  17.         assignments['Q'] = positions.pop
  18.         assignments['N1'] = positions.pop
  19.         assignments['N2'] = positions.pop
  20.  
  21.         positions.sort!
  22.  
  23.         assignments['K'] = positions[1]
  24.         assignments['R1'] = positions[0]
  25.         assignments['R2'] = positions[2]
  26.  
  27.         positions = String.new
  28.         pieces = String.new
  29.  
  30.         assignments.sort_by { |k, v| v}.each do |k, v|
  31.                 pieces << k[0] + " "
  32.                 positions << v.to_s + " "
  33.         end
  34.  
  35.         #puts positions
  36.         return pieces
  37. end
  38.  
  39. puts assignment
clone this paste RAW Paste Data