#!/usr/bin/env ruby
require File.expand_path('../../../config/environment', __FILE__)

Swars::Battle.destroy_all
Swars::User.destroy_all

user1 = Swars::User.create!(:key => "DevUser1")
user2 = Swars::User.create!(:key => "DevUser2")
record = Swars::Battle.new
record.final_key = :TIMEOUT
record.memberships.build(user: user1)
record.memberships.build(user: user2)
record.save!
record.memberships[1].leave_alone_seconds # => 10 minutes and -10 seconds
record.memberships[0].think_max           # => 5
record.memberships[1].think_max           # => 590
record.memberships[0].time_chart_xy_list  # => [{:x=>1, :y=>1 second}, {:x=>3, :y=>5 seconds}, {:x=>5, :y=>2 seconds}]
record.memberships[1].time_chart_xy_list  # => [{:x=>2, :y=>-3 seconds}, {:x=>4, :y=>-7 seconds}, {:x=>6, :y=>-10 minutes and 10 seconds}]
record.time_chart_label_max               # => 6

tp Swars::User
tp Swars::Battle
# >> |-----+----------+----------+-------------------+-------------------+---------------------------+---------------------------|
# >> | id  | user_key | grade_id | last_reception_at | search_logs_count | created_at                | updated_at                |
# >> |-----+----------+----------+-------------------+-------------------+---------------------------+---------------------------|
# >> | 174 | DevUser1 |       40 |                   |                 0 | 2020-03-14 13:40:53 +0900 | 2020-03-14 13:40:53 +0900 |
# >> | 175 | DevUser2 |       40 |                   |                 0 | 2020-03-14 13:40:53 +0900 | 2020-03-14 13:40:53 +0900 |
# >> |-----+----------+----------+-------------------+-------------------+---------------------------+---------------------------|
# >> |-----+---------+---------------------------+----------+--------------------------------------------------------------------------------------------+-----------+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+---------------+---------------------------+---------------------------+------------+------------+---------------+------------+--------------------------------------------------+------------+----------------------------------+------------------+-----------------+--------------------+---------------+----------------+--------------------|
# >> | id  | key     | battled_at                | rule_key | csa_seq                                                                                    | final_key | win_user_id | turn_max | meta_info                                                                                                                                                                                                                                                                                                                                  | accessed_at               | outbreak_turn | created_at                | updated_at                | preset_key | start_turn | critical_turn | saturn_key | sfen_body                                        | image_turn | sfen_hash                        | defense_tag_list | attack_tag_list | technique_tag_list | note_tag_list | other_tag_list | kifu_body_for_test |
# >> |-----+---------+---------------------------+----------+--------------------------------------------------------------------------------------------+-----------+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+---------------+---------------------------+---------------------------+------------+------------+---------------+------------+--------------------------------------------------+------------+----------------------------------+------------------+-----------------+--------------------+---------------+----------------+--------------------|
# >> | 173 | alice-bob-20000101_000000 | 2020-03-14 13:40:53 +0900 | ten_min  | [["+7968GI", 599], ["-8232HI", 597], ["+5756FU", 594], ["-3334FU", 590], ["+6857GI", 592]] | TIMEOUT   |         174 |        5 | {:header=>{"先手"=>"DevUser1 30級", "後手"=>"DevUser2 30級", "開始日時"=>"2020/03/14 13:40:53", "棋戦"=>"将棋ウォーズ(10分切れ負け)", "場所"=>"https://shogiwars.heroz.jp/games/alice-bob-20000101_000000", "持ち時間"=>"00:10+00", "先手の戦型"=>"嬉野流", "後手の戦型"=>"△３ニ飛戦法", "先手の備考"=>"居飛車, 対振り飛車, 対抗形, 居玉, 相居玉", "後手の備... | 2020-03-14 13:40:53 +0900 |               | 2020-03-14 13:40:53 +0900 | 2020-03-14 13:40:53 +0900 | 平手       |            |               | public     | position startpos moves 7i6h 8b3b 5g5f 3c3d 6h5g |            | 3867ed2691237d42c7df0bd43fbb5661 |                  |                 |                    |               |                |                    |
# >> |-----+---------+---------------------------+----------+--------------------------------------------------------------------------------------------+-----------+-------------+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+---------------+---------------------------+---------------------------+------------+------------+---------------+------------+--------------------------------------------------+------------+----------------------------------+------------------+-----------------+--------------------+---------------+----------------+--------------------|
