bugfix: safety against breaking the AI if you press undo while it's thinking
[kaya.git] / lib / plugins / shogi / shogi.rb
blob22203976f62d19ded345425fb93961205aa4f905
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'plugins/plugin'
9 require 'require_bundle'
10 require_bundle 'shogi', 'state'
11 require_bundle 'shogi', 'pool'
12 require_bundle 'shogi', 'move'
13 require_bundle 'shogi', 'validator'
14 require_bundle 'shogi', 'serializer'
15 require_bundle 'shogi', 'notation'
16 require_bundle 'shogi', 'piece'
17 require_bundle 'shogi', 'psn'
18 require_bundle 'shogi', 'policy'
19 require 'games/game_actions'
20 require 'lazy'
22 module Shogi
24 class Game
25   include Plugin
26   include GameActions
27   
28   plugin :name => KDE::i18n('Shogi'),
29          :id => :shogi,
30          :interface => :game,
31          :category => 'Shogi',
32          :depends => [:chess]
33   
34   attr_reader :size, :state, :board, :pool,
35               :policy, :move, :animator, :validator,
36               :piece, :players, :types, :serializer,
37               :notation, :game_writer, :game_extensions
38               
39   def initialize
40     @size = Point.new(9, 9)
41     @state = Factory.new { State.new(board.new, pool, move, piece) }
42     @board = Factory.new { chess.board.component.new size }
43     @pool = Pool
44     @piece = Piece
45     @move = Move
46     @validator = Validator
47     @animator = chess.animator
48     @policy = Factory.new(Policy) { Policy.new(move, validator, true) }
49     
50     @players = [:black, :white]
51     @types = [:pawn, :lance, :horse, :silver, 
52               :gold, :bishop, :rook, :king]
53               
54     @serializer = Factory.new(Serializer) {|rep| 
55       Serializer.new(rep, validator, move, piece, notation) }
56     @notation = promise { Notation.new(piece, size) }
57     
58     @game_writer = promise { PSN.new(serializer.new(:compact), state) }
59     @game_extensions = %w(psn)
60               
61     action :autopromote, 
62            :checked => true,
63            :text => '&Promote Automatically' do |value, policy|
64       policy.autopromote = value
65     end
66   end
67   
68   def game_reader
69     @game_writer
70   end
71 end
73 end
75 module MiniShogi
77 class Game < Shogi::Game
78   plugin :name => KDE::i18n('MiniShogi'),
79          :id => :minishogi,
80          :interface => :game,
81          :category => 'Shogi'
83   def initialize
84     super
85     @size = Point.new(5, 5)
86     @state = Factory.new { State.new(board.new, pool, move, piece) }
87     @game_extensions = []
88   end
90 end
92 end