Class: Mjai::TenhouArchive::TenhouFuro
- Inherits:
-
Object
- Object
- Mjai::TenhouArchive::TenhouFuro
show all
- Includes:
- Util
- Defined in:
- lib/mjai/tenhou_archive.rb
Overview
Constant Summary
Constants included
from Util
Util::YAKU_ID_TO_NAME
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Util
compose_pid, decompose_pid, #delete_tehai_by_pid, get_pai, #get_points_params, #on_tenhou_event, #path, pid_to_pai, #verify_tenhou_tehais
Constructor Details
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
# File 'lib/mjai/tenhou_archive.rb', line 299
def initialize(fid)
@num = fid
@target_dir = read_bits(2)
if read_bits(1) == 1
parse_chi()
return
end
if read_bits(1) == 1
parse_pon()
return
end
if read_bits(1) == 1
parse_kakan()
return
end
if read_bits(1) == 1
parse_nukidora()
return
end
parse_kan()
end
|
Instance Attribute Details
#consumed_pids ⇒ Object
Returns the value of attribute consumed_pids.
321
322
323
|
# File 'lib/mjai/tenhou_archive.rb', line 321
def consumed_pids
@consumed_pids
end
|
#taken_pid ⇒ Object
Returns the value of attribute taken_pid.
321
322
323
|
# File 'lib/mjai/tenhou_archive.rb', line 321
def taken_pid
@taken_pid
end
|
#target_dir ⇒ Object
Returns the value of attribute target_dir.
321
322
323
|
# File 'lib/mjai/tenhou_archive.rb', line 321
def target_dir
@target_dir
end
|
#type ⇒ Object
Returns the value of attribute type.
321
322
323
|
# File 'lib/mjai/tenhou_archive.rb', line 321
def type
@type
end
|
Instance Method Details
#parse_chi ⇒ Object
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
# File 'lib/mjai/tenhou_archive.rb', line 336
def parse_chi()
cids = (0...3).map(){ |i| read_bits(2) }
read_bits(1)
pattern = read_bits(6)
seq_kind = pattern / 3
taken_pos = pattern % 3
pai_type = seq_kind / 7
first_number = seq_kind % 7 + 1
@type = :chi
@consumed_pids = []
for i in 0...3
pid = compose_pid(pai_type, first_number + i, cids[i])
if i == taken_pos
@taken_pid = pid
else
@consumed_pids.push(pid)
end
end
end
|
#parse_kakan ⇒ Object
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
# File 'lib/mjai/tenhou_archive.rb', line 396
def parse_kakan()
taken_cid = read_bits(2)
read_bits(2)
pattern = read_bits(7)
pai_kind = pattern / 3
taken_pos = pattern % 3
pai_type = pai_kind / 9
pai_number = pai_kind % 9 + 1
@type = :kakan
@target_dir = 0
@consumed_pids = []
for i in 0...4
pid = compose_pid(pai_type, pai_number, i)
if i == taken_cid
@taken_pid = pid
else
@consumed_pids.push(pid)
end
end
end
|
#parse_kan ⇒ Object
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
# File 'lib/mjai/tenhou_archive.rb', line 380
def parse_kan()
read_bits(2)
pid = read_bits(8)
(pai_type, pai_number, key_cid) = decompose_pid(pid)
@type = @target_dir == 0 ? :ankan : :daiminkan
@consumed_pids = []
for i in 0...4
pid = compose_pid(pai_type, pai_number, i)
if i == key_cid && @type != :ankan
@taken_pid = pid
else
@consumed_pids.push(pid)
end
end
end
|
#parse_pon ⇒ Object
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
# File 'lib/mjai/tenhou_archive.rb', line 356
def parse_pon()
read_bits(1)
unused_cid = read_bits(2)
read_bits(2)
pattern = read_bits(7)
pai_kind = pattern / 3
taken_pos = pattern % 3
pai_type = pai_kind / 9
pai_number = pai_kind % 9 + 1
@type = :pon
@consumed_pids = []
j = 0
for i in 0...4
next if i == unused_cid
pid = compose_pid(pai_type, pai_number, i)
if j == taken_pos
@taken_pid = pid
else
@consumed_pids.push(pid)
end
j += 1
end
end
|
#read_bits(num_bits) ⇒ Object
417
418
419
420
421
422
|
# File 'lib/mjai/tenhou_archive.rb', line 417
def read_bits(num_bits)
mask = (1 << num_bits) - 1
result = @num & mask
@num >>= num_bits
return result
end
|
#to_action(game, actor) ⇒ Object
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/mjai/tenhou_archive.rb', line 323
def to_action(game, actor)
params = {
:type => @type,
:actor => actor,
:pai => pid_to_pai(@taken_pid),
:consumed => @consumed_pids.map(){ |pid| pid_to_pai(pid) },
}
if ![:ankan, :kakan].include?(@type)
params[:target] = game.players[(actor.id + @target_dir) % 4]
end
return Action.new(params)
end
|