-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
57 lines (46 loc) · 1.08 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'sinatra'
require 'open-uri'
LG_PGN_URL = 'http://www.littlegolem.net/jsp/game/png.jsp'
LG_GAME_URL = 'http://www.littlegolem.net/jsp/game/game.jsp'
VARIANT_8x8_RE = /Lines of Action-Size 8x8/
VARIANT_BLACKHOLE_RE = /Lines of Action-Black Hole/
VARIANT_SCRAMBLE_RE = /Lines of Action-Scramble/
VARIANT_QUICK_RE = /Lines of Action-Quick/
def detect_loa_variant(url)
open(url) do |f|
f.each_line do |line|
case line
when VARIANT_8x8_RE
return '8x8'
when VARIANT_BLACKHOLE_RE
return 'BlackHole'
when VARIANT_SCRAMBLE_RE
return 'Scramble'
when VARIANT_QUICK_RE
return 'Quick'
end
end
return 'Unknown'
end
end
def render_game(id)
$game_id = id
pgn_url = "#{LG_PGN_URL}?gid=#{id}"
$pgn = open(pgn_url).read().gsub(/\r|\n/, "")
game_url = "#{LG_GAME_URL}?gid=#{id}"
$variant = detect_loa_variant(game_url)
erb :index
end
get '/' do
$pgn = ''
$variant = '8x8'
erb :index
end
get '/lg/:id' do
id = params[:id]
render_game(id)
end
get '/lg-:id' do
id = params[:id]
render_game(id)
end