Обеспечение всемирной трансляции спортивных шахматных соревнований с применением разработанного в ходе проекта законченного программного продукта
Характеристика структурного подразделения "Шахматный клуб". Выбор основных методологий, инструментальных средств и расчет затрат на разработку специализированного шахматного программного обеспечения ИС "ШК". Оценка экономической эффективности проекта.
Рубрика | Программирование, компьютеры и кибернетика |
Вид | дипломная работа |
Язык | русский |
Дата добавления | 29.06.2010 |
Размер файла | 5,6 M |
Отправить свою хорошую работу в базу знаний просто. Используйте форму, расположенную ниже
Студенты, аспиранты, молодые ученые, использующие базу знаний в своей учебе и работе, будут вам очень благодарны.
html << "<td>" + tournament.name + "</td>"
html << "<td>" + (city.nil? ? "" : city.name) + "</td>"
html << "</tr>"
end
html
end
def render_game_info
"Тестовая партия из тестового турнира"
end
def render_moves
moves = "<div id=\"moves\"></div>"
moves = "<table width='100%' align='center'>"
moves += "<tr><th width='2%'></th><th width='45%'></th><th ></th><th width='45%'></th><th width='2%'></th></tr>"
moves += "<tr><td>1.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>2.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>3.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>4.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>5.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>6.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>7.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>8.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>9.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>10.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>11.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>12.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>13.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>14.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>15.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>16.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>17.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>18.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>19.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td>20.</td><td>b</td><td>c</td><td>d</td><td>e</td></tr>"
moves += "<tr><td colspan='5' align='center'>"
moves += image_tag('go_begin.jpg', :id => 'go_begin', :onclick => 'goBegin();'), :onmouseover => 'new Effect.Scale("go_begin", 110)'), :onmouseout => 'new Effect.Scale("go_begin", 90)') + ' '
moves += image_tag('go_prev.jpg', :id => 'go_prev', :onclick => 'goPrev();') :onmouseover => 'new Effect.Scale("go_prev", 110)', :onmouseout => 'new Effect.Scale("go_prev", 90)') + ' '
moves += image_tag('go_refresh.jpg', :id => 'go_refresh', :onclick => 'goRefresh();') :onmouseover => 'new Effect.Scale("go_refresh", 110)', :onmouseout => 'new Effect.Scale("go_refresh", 90)') + ' '
moves += image_tag('go_next.jpg', :id => 'go_next', :onclick => 'goNext();'):onmouseover => 'new Effect.Scale("go_next", 110)', :onmouseout => 'new Effect.Scale("go_next", 90)') + ' '
moves += image_tag('go_end.jpg', :id => 'go_end', :onclick => 'goEnd();')#:onmouseover => 'new Effect.Scale("go_end", 110)', :onmouseout => 'new Effect.Scale("go_end", 90)') + ' '
moves += "</td></tr>"
moves += "</table>";
moves
end
def render_board
return "<table class=\"board\" id=\"board\">
<tr>
<td class=\"board_label_digit\">8</td>
<td class=\"board_white_field\" id=\"fieldA8\"></td>
<td class=\"board_black_field\" id=\"fieldB8\"></td>
<td class=\"board_white_field\" id=\"fieldC8\"></td>
<td class=\"board_black_field\" id=\"fieldD8\"></td>
<td class=\"board_white_field\" id=\"fieldE8\"></td>
<td class=\"board_black_field\" id=\"fieldF8\"></td>
<td class=\"board_white_field\" id=\"fieldG8\"></td>
<td class=\"board_black_field\" id=\"fieldH8\"></td>
</tr>
<tr>
<td class=\"board_label_digit\">7</td>
<td class=\"board_black_field\" id=\"fieldA7\"></td>
<td class=\"board_white_field\" id=\"fieldB7\"></td>
<td class=\"board_black_field\" id=\"fieldC7\"></td>
<td class=\"board_white_field\" id=\"fieldD7\"></td>
<td class=\"board_black_field\" id=\"fieldE7\"></td>
<td class=\"board_white_field\" id=\"fieldF7\"></td>
<td class=\"board_black_field\" id=\"fieldG7\"></td>
<td class=\"board_white_field\" id=\"fieldH7\"></td>
</tr>
<tr>
<td class=\"board_label_digit\">6</td>
<td class=\"board_white_field\" id=\"fieldA6\"></td>
<td class=\"board_black_field\" id=\"fieldB6\"></td>
<td class=\"board_white_field\" id=\"fieldC6\"></td>
<td class=\"board_black_field\" id=\"fieldD6\"></td>
<td class=\"board_white_field\" id=\"fieldE6\"></td>
<td class=\"board_black_field\" id=\"fieldF6\"></td>
<td class=\"board_white_field\" id=\"fieldG6\"></td>
<td class=\"board_black_field\" id=\"fieldH6\"></td>
</tr>
<tr>
<td class=\"board_label_digit\">5</td>
<td nowrap class=\"board_black_field\" id=\"fieldA5\"></td>
<td nowrap class=\"board_white_field\" id=\"fieldB5\"></td>
<td nowrap class=\"board_black_field\" id=\"fieldC5\"></td>
<td nowrap class=\"board_white_field\" id=\"fieldD5\"></td>
<td nowrap class=\"board_black_field\" id=\"fieldE5\"></td>
<td nowrap class=\"board_white_field\" id=\"fieldF5\"></td>
<td nowrap class=\"board_black_field\" id=\"fieldG5\"></td>
<td nowrap class=\"board_white_field\" id=\"fieldH5\"></td>
</tr>
<tr>
<td class=\"board_label_digit\">4</td>
<td class=\"board_white_field\" id=\"fieldA4\"></td>
<td class=\"board_black_field\" id=\"fieldB4\"></td>
<td class=\"board_white_field\" id=\"fieldC4\"></td>
<td class=\"board_black_field\" id=\"fieldD4\"></td>
<td class=\"board_white_field\" id=\"fieldE4\"></td>
<td class=\"board_black_field\" id=\"fieldF4\"></td>
<td class=\"board_white_field\" id=\"fieldG4\"></td>
<td class=\"board_black_field\" id=\"fieldH4\"></td>
</tr>
<tr>
<td class=\"board_label_digit\">3</td>
<td class=\"board_black_field\" id=\"fieldA3\"></td>
<td class=\"board_white_field\" id=\"fieldB3\"></td>
<td class=\"board_black_field\" id=\"fieldC3\"></td>
<td class=\"board_white_field\" id=\"fieldD3\"></td>
<td class=\"board_black_field\" id=\"fieldE3\"></td>
<td class=\"board_white_field\" id=\"fieldF3\"></td>
<td class=\"board_black_field\" id=\"fieldG3\"></td>
<td class=\"board_white_field\" id=\"fieldH3\"></td>
</tr>
<tr>
<td class=\"board_label_digit\">2</td>
<td class=\"board_white_field\" id=\"fieldA2\"></td>
<td class=\"board_black_field\" id=\"fieldB2\"></td>
<td class=\"board_white_field\" id=\"fieldC2\"></td>
<td class=\"board_black_field\" id=\"fieldD2\"></td>
<td class=\"board_white_field\" id=\"fieldE2\"></td>
<td class=\"board_black_field\" id=\"fieldF2\"></td>
<td class=\"board_white_field\" id=\"fieldG2\"></td>
<td class=\"board_black_field\" id=\"fieldH2\"></td>
</tr>
<tr>
<td class=\"board_label_digit\">1</td>
<td class=\"board_black_field\" id=\"fieldA1\"></td>
<td class=\"board_white_field\" id=\"fieldB1\"></td>
<td class=\"board_black_field\" id=\"fieldC1\"></td>
<td class=\"board_white_field\" id=\"fieldD1\"></td>
<td class=\"board_black_field\" id=\"fieldE1\"></td>
<td class=\"board_white_field\" id=\"fieldF1\"></td>
<td class=\"board_black_field\" id=\"fieldG1\"></td>
<td class=\"board_white_field\" id=\"fieldH1\"></td>
</tr>
<tr>
<td class=\"board_lebel_letter\"> </td>
<td class=\"board_lebel_letter\">A</td>
<td class=\"board_lebel_letter\">B</td>
<td class=\"board_lebel_letter\">C</td>
<td class=\"board_lebel_letter\">D</td>
<td class=\"board_lebel_letter\">E</td>
<td class=\"board_lebel_letter\">F</td>
<td class=\"board_lebel_letter\">G</td>
<td class=\"board_lebel_letter\">H</td>
</tr>
</table>"
end
def render_result
"1/2 - 1/2"
end
def render_black_time
"-:--:--"
end
def render_white_time
"-:--:--"
end
end
Представление (view)
layout/main.rhtml
---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Стартовая страница: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
<%= stylesheet_link_tag 'main' %>
<%= stylesheet_link_tag 'game' %>
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag 'game' %>
</head>
<body style='background-color: #000000'>
<table bgcolor="#f4f4f4" border="0" width="80%" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td width='3%'></td>
<td>
<h1><%= link_to(image_tag('dgt.gif', :size => '42x25', :border => 0, :alt => 'http://dgtprojects.com'), 'http://dgtprojects.com') %>
Сервер трансляции шахматных партий <%= link_to 'rDGT', 'http://rdgt.org' %>
<%= link_to(image_tag('home.gif', :size => '12x12', :border => 0), '/main/index') %>
<%= link_to(image_tag('email.gif', :size => '12x12', :border => 0), '') %>
<%= link_to(image_tag('search.gif', :size => '12x12', :border => 0), '')%>
</h1><hr />
</td>
<td width='3%'></td>
</tr>
<tr>
<td></td>
<td>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td align="right"><br /><hr />
<%= mail_to 'zarstudio@gmail.com', '[ Разработчики ]' %><br />
</td>
<td></td>
</tr>
</table>
</body>
</html>
main/enter.rhtml
---
<% form_tag '/main/login' do %>
<table align='center' width='100%'>
<tr>
<td width='41%' align="right"><strong>Имя: <strong></td>
<td align="left"><%= text_field_tag :login, params[:login] %></td>
</tr>
<tr>
<td align="right"><strong>Пароль: </strong></td>
<td align="left"><%= password_field_tag :password, params[:password] %></td>
</tr>
<tr>
<td align="center" colspan="2"><%= submit_tag 'Войти' %></td>
</tr>
<tr>
<td align="center" colspan="2"><%= link_to '[ Регистрация ]', { :action => 'register' }%></td>
</tr>
<tr>
<td align="center" colspan="2"><%= link_to '[ Забыли логин или пароль? ]', { :action => 'remind' }%></td>
</tr>
</table>
<% end %>
<br />
main/game.rhtml
---
<%= render_game_info %>
<br />
<br />
<table width='100%' cellspacing="0" cellpadding="0" border="0" id='table_board'>
<tr align="center">
<td width='1%'></td>
<td width='50%' align="left"><%= image_tag 'seek_black.png', :size => '16x16' %></td>
<td></td>
<td width='45%'><%= link_to @game.black_player.to_s, { :controller => 'players', :action => 'show', :id => @game.black_player.id } %></td>
<td width='1%'></td>
</tr>
<tr align="center">
<td></td>
<td></td>
<td></td>
<td><%= render_black_time %></td>
<td></td>
</tr>
<tr>
<td></td>
<td><%= render_board %></td>
<td></td>
<td style="background-color: #dadada"><%= render_moves %></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td></td>
<td></td>
<td><%= render_white_time%></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td align="left"><%= image_tag 'seek_white.png', :size => '16x16' %></td>
<td></td>
<td><%= link_to @game.white_player.to_s, { :controller => 'players', :action => 'show', :id => @game.white_player.id} %></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td></td>
<td></td>
<td><%= render_result %></td>
<td></td>
</tr>
<tr>
<td colspan="5"></td>
</tr>
</table>
<%= link_to_remote 'Обновить', :update => 'moves', :url => { :action => 'game_moves', :id => @game.id } %>
<div id='debug'></div>
main/logo.rhtml
---
<table align='center'><tr><td align='center'>
<%= image_tag 'logo.jpg', :alt => 'Шахматный портал rDGT', :width => '400px', :height => '280px' %>
<br />
<br /><%= link_to '[ Трансляции ]', { :action => 'online' }%>
<br /><%= link_to '[ Турниры ]' , { :action => 'offline' }%>
<br /><%= link_to '[ Кабинет ]', { :action => 'enter' } %>
</td></tr></table>
main/online.rhtml
---
<!-- <%= link_to '[ Просмотр ]', { :action => 'game' }%>-->
<table width='80%' align='center'>
<tr>
<th></th>
<th width='10%'>Начало</th>
<th width='25%'>Турнир</th>
<th width='30%'>Белые</th>
<th width='30%'>Черные</th>
</tr>
<% @online_games.each do |game| %>
<tr align='center'>
<td class='td_info'><%= link_to(image_tag('eye.gif', :size => '16x16', :onclick => '', :alt => 'Просмотр трансляции'), { :action => 'game', :id => game.id }) %></td>
<td class='td_info'><%= game.begin.to_s %></td>
<td class='td_info'><%= link_to game.tournament.to_s, { :controller => 'tournaments', :action => 'show', :id => game.tournament.id } %></td>
<td class='td_info'><%= link_to game.white.to_s, { :controller => 'players', :action => 'show', :id => game.white.id } %></td>
<td class='td_info'><%= link_to game.black.to_s, { :controller => 'players', :action => 'show', :id => game.black.id } %></td>
</tr>
<% end %>
</table>
Модель (model)
---
class Cities < ActiveRecord::Base
end
class City < ActiveRecord::Base
end
class ClockReglament < ActiveRecord::Base
end
class Country < ActiveRecord::Base
end
class CurrentGame < ActiveRecord::Base
def init
@game = Game.find(self.game_id) if @game.nil?
end
def tournament
init
@game.tournament
end
def white
init
@game.white_player
end
def black
init
@game.black_player
end
end
class Game < ActiveRecord::Base
def moves
result = ""
@moves = Move.find_all_by_game_id self.id
@moves.sort { |movea, moveb| movea.number <=> moveb.number }.each do |move|
result += move.to_s + "|"
end
result
end
def tournament
info = GameInfo.find self.game_info_id unless self.game_info_id.nil?
t = Tournament.find info.tournament_id
end
def white_player
player = Player.new
player.id= 1
player.first_name = "Иван"
player.second_name = "Рыков"
player
end
def black_player
player = Player.new
player.id= 1
player.first_name = "Сергей"
player.second_name = "Бедарев"
player
end
end
class GameInfo < ActiveRecord::Base
end
class LastMove < ActiveRecord::Base
end
class Move < ActiveRecord::Base
def to_s
((self.white_move.nil? or self.white_move == "") ? "******" : self.white_move) +
((self.black_move.nil? or self.black_move == "") ? "******" : self.black_move) + ":" +
(self.white_clock.nil? ? "" : self.white_clock) + "-" + (self.black_clock.nil? ? "" : self.black_clock)
end
end
class Player < ActiveRecord::Base
def full_name
return self.second_name + " " + self.first_name
end
def to_s
full_name
end
end
class Tournament < ActiveRecord::Base
def to_s
self.name
end
end
class TournamentView < ActiveRecord::Base
end
require 'digest/md5'
class User < ActiveRecord::Base
validates_presence_of :login
validates_uniqueness_of :login
def self.authenticate(login, password)
user = User.find_by_name(login)
if user
expected_password = encrypted_password(password)
if user.password != expected_password
user = nil
end
end
user
end
def self.encrypted_password(password)
Digest::MD5.hexdigest("sdjkvkjeho2ijij2o3d2kn3dl2kn3dn23dkn2ld3n" + password)
end
end
Миграция (db migration)
---
ActiveRecord::Schema.define(:version => 12) do
create_table "cities", :force => true do |t|
t.column "name", :string, :limit => 30
t.column "country_id", :integer
t.column "description", :text
t.column "image", :binary
end
create_table "clock_reglaments", :force => true do |t|
t.column "title", :string, :limit => 30
t.column "total_time", :integer
t.column "add", :boolean, :limit => nil, :default => false
t.column "add_time", :integer, :default => 0
t.column "desciprion", :text
end
create_table "countries", :force => true do |t|
t.column "name", :string, :limit => 30
t.column "code", :string, :limit => 30
t.column "image", :binary
t.column "description", :text
end
create_table "current_games", :force => true do |t|
t.column "game_id", :integer
t.column "begin", :datetime
t.column "end", :datetime
t.column "description", :text
end
create_table "game_infos", :force => true do |t|
t.column "game_id", :integer
t.column "white_id", :integer
t.column "black_id", :integer
t.column "tournament_id", :integer
t.column "result", :integer
t.column "clock_reglament_id", :integer
t.column "round", :integer
t.column "debut_code", :string, :limit => 30
t.column "description", :text
t.column "status", :string, :limit => 30
end
create_table "games", :force => true do |t|
t.column "game_info_id", :integer
t.column "begin", :datetime
t.column "end", :datetime
t.column "desciption", :text
end
create_table "last_moves", :force => true do |t|
t.column "move_id", :integer
t.column "move_time", :datetime
end
create_table "moves", :force => true do |t|
t.column "number", :integer
t.column "game_id", :integer
t.column "white_move", :string, :limit => 6
t.column "black_move", :string, :limit => 6
t.column "white_clock", :float
t.column "black_clock", :float
t.column "white_comment", :text
t.column "black_comment", :text
end
create_table "players", :force => true do |t|
t.column "first_name", :string, :limit => 30
t.column "second_name", :string, :limit => 30
t.column "country_id", :integer
t.column "burn_date", :datetime
t.column "fide_rating", :integer
t.column "photo", :binary
t.column "description", :text
end
create_table "tournament_views", :force => true do |t|
t.column "name", :string, :limit => 30
t.column "system", :string, :limit => 30
t.column "is_match", :boolean, :limit => nil, :default => false
t.column "is_command", :boolean, :limit => nil, :default => false
t.column "total_games", :integer, :default => 0
t.column "total_rounds", :integer, :default => 0
t.column "description", :text
end
create_table "tournaments", :force => true do |t|
t.column "name", :string, :limit => 30
t.column "category", :integer
t.column "city_id", :integer
t.column "begin_date", :datetime
t.column "end_date", :datetime
t.column "tournament_view_id", :integer
t.column "status", :string, :limit => 30
t.column "description", :text
end
create_table "users", :force => true do |t|
t.column "login", :string, :limit => 30
t.column "password", :string, :limit => 50
t.column "name", :string, :limit => 30
t.column "is_admin", :boolean, :limit => nil, :default => false
t.column "email", :string, :limit => 30
t.column "webpage", :string, :limit => 30
t.column "desciption", :text
end
end
Javascript (javascript) - осуществляют демонстрацию шахматной партии, при помощи технологии AJAX обращаясь за обновлениями позиции на rDGT сервер.
game.js
---
var images = 'http://localhost:3000/images/classic/';
var moves_url = '/main/game_moves/1';
// Фигура
function figure(id, color, type, current_field, last_field, alive, board) {
this.id = id;
this.color = color;
this.type = type;
this.current_field = current_field;
this.last_field = last_field;
this.alive = alive;
this.set_field = set_field;
this.do_move = do_move;
this.reload = reload;
this.img = document.createElement('img');
this.img.id = this.id;
this.board = board;
this.reload();
//trace('create figure [' + this.id + ']');
}
// Поле
function field(id, color, vertical, horizontal, figure, board) {
this.id = id;
this.color = color;
this.vertical = vertical;
this.horizontal = horizontal;
this.figure = figure;
this.board = board;
this.repaint = repaint;
//trace('create field [' + this.id + ']');
}
// Ход
function move(number, color, from_field, to_field, figure, alive_figure, is_short_castling, is_long_castling, prev_move, next_move, board, time) {
this.number = number;
this.color = color;
this.from_field = from_field;
this.to_field = to_field;
this.figure = figure;
this.alive_figure = alive_figure;
this.forward = forward;
this.backward = backward;
this.is_short_castling = is_short_castling;
this.is_long_castling = is_long_castling;
this.prev_move = prev_move;
this.next_move = next_move;
this.board = board;
this.white_time = white_time;
this.black_time = black_time;
}
// Коллекция ходов
function move_collection(board) {
this.board = board;
this.get_move = function(color, number) {
return color == 'white' ? this.moves[(number * 2) - 1] : this.moves[number * 2];
}
this.exists_move = function(color, number) {
return get_move(color, number) != null;
}
this.get_current_move = function() {
return this.current_move;
}
this.add_move = function(move) {
trace('add move: ' + move.number + " " + moveBy.color);
if(current_move == null) {
this.first_move = move;
this.current_move = move;
} else {
move.prev_move = this.current_move;
this.current_move.next_move = move;
this.current_move = move;
}
this.moves.push(move);
}
this.first_move = null;
this.current_move = null;
this.moves = new Array();
}
// Коллекция фигур
function figure_collection(board) {
this.board = board;
this.wpA = new figure('wpA', 'white', 'pawn', null, null, true, board);
this.wpB = new figure('wpB', 'white', 'pawn', null, null, true, board);
this.wpC = new figure('wpC', 'white', 'pawn', null, null, true, board);
this.wpD = new figure('wpD', 'white', 'pawn', null, null, true, board);
this.wpE = new figure('wpE', 'white', 'pawn', null, null, true, board);
this.wpF = new figure('wpF', 'white', 'pawn', null, null, true, board);
this.wpG = new figure('wpG', 'white', 'pawn', null, null, true, board);
this.wpH = new figure('wpH', 'white', 'pawn', null, null, true, board);
this.wrA = new figure('wrA', 'white', 'rook', null, null, true, board);
this.wrH = new figure('wrH', 'white', 'rook', null, null, true, board);
this.whB = new figure('whB', 'white', 'horse', null, null, true, board);
this.whG = new figure('whG', 'white', 'horse', null, null, true, board);
this.wbC = new figure('wbC', 'white', 'bishop', null, null, true, board);
this.wbF = new figure('wbF', 'white', 'bishop', null, null, true, board);
this.wq = new figure('wq', 'white', 'queen', null, null, true, board);
this.wk = new figure('wk', 'white', 'king', null, null, true, board);
this.bpA = new figure('bpA', 'black', 'pawn', null, null, true, board);
this.bpB = new figure('bpB', 'black', 'pawn', null, null, true, board);
this.bpC = new figure('bpC', 'black', 'pawn', null, null, true, board);
this.bpD = new figure('bpD', 'black', 'pawn', null, null, true, board);
this.bpE = new figure('bpE', 'black', 'pawn', null, null, true, board);
this.bpF = new figure('bpF', 'black', 'pawn', null, null, true, board);
this.bpG = new figure('bpG', 'black', 'pawn', null, null, true, board);
this.bpH = new figure('bpH', 'black', 'pawn', null, null, true, board);
this.brA = new figure('brA', 'black', 'rook', null, null, true, board);
this.brH = new figure('brH', 'black', 'rook', null, null, true, board);
this.bhB = new figure('bhB', 'black', 'horse', null, null, true, board);
this.bhG = new figure('bhG', 'black', 'horse', null, null, true, board);
this.bbC = new figure('bbC', 'black', 'bishop', null, null, true, board);
this.bbF = new figure('bbF', 'black', 'bishop', null, null, true, board);
this.bq = new figure('bq', 'black', 'queen', null, null, true, board);
this.bk = new figure('bk', 'black', 'king', null, null, true, board);
}
// Коллекция полей шахматной доски
function field_collection(board) {
this.get_field = get_field;
this.board = board;
this.toArray = function() {
return [this.A1, this.A2, this.A3, this.A4, this.A5, this.A6, this.A7, this.A8,
this.B1, this.B2, this.B3, this.B4, this.B5, this.B6, this.B7, this.B8,
this.C1, this.C2, this.C3, this.C4, this.C5, this.C6, this.C7, this.C8,
this.D1, this.D2, this.D3, this.D4, this.D5, this.D6, this.D7, this.D8,
this.E1, this.E2, this.E3, this.E4, this.E5, this.E6, this.E7, this.E8,
this.F1, this.F2, this.F3, this.F4, this.F5, this.F6, this.F7, this.F8,
this.G1, this.G2, this.G3, this.G4, this.G5, this.G6, this.G7, this.G8,
this.H1, this.H2, this.H3, this.H4, this.H5, this.H6, this.H7, this.H8];
}
this.A1 = new field('fieldA1', 'black', 'A', '1', null, board);
this.B1 = new field('fieldB1', 'white', 'B', '1', null, board);
this.C1 = new field('fieldC1', 'black', 'C', '1', null, board);
this.D1 = new field('fieldD1', 'white', 'D', '1', null, board);
this.E1 = new field('fieldE1', 'black', 'E', '1', null, board);
this.F1 = new field('fieldF1', 'white', 'F', '1', null, board);
this.G1 = new field('fieldG1', 'black', 'G', '1', null, board);
this.H1 = new field('fieldH1', 'white', 'H', '1', null, board);
this.A2 = new field('fieldA2', 'white', 'A', '2', null, board);
this.B2 = new field('fieldB2', 'black', 'B', '2', null, board);
this.C2 = new field('fieldC2', 'white', 'C', '2', null, board);
this.D2 = new field('fieldD2', 'black', 'D', '2', null, board);
this.E2 = new field('fieldE2', 'white', 'E', '2', null, board);
this.F2 = new field('fieldF2', 'black', 'F', '2', null, board);
this.G2 = new field('fieldG2', 'white', 'G', '2', null, board);
this.H2 = new field('fieldH2', 'black', 'H', '2', null, board);
this.A3 = new field('fieldA3', 'black', 'A', '3', null, board);
this.B3 = new field('fieldB3', 'white', 'B', '3', null, board);
this.C3 = new field('fieldC3', 'black', 'C', '3', null, board);
this.D3 = new field('fieldD3', 'white', 'D', '3', null, board);
this.E3 = new field('fieldE3', 'black', 'E', '3', null, board);
this.F3 = new field('fieldF3', 'white', 'F', '3', null, board);
this.G3 = new field('fieldG3', 'black', 'G', '3', null, board);
this.H3 = new field('fieldH3', 'white', 'H', '3', null, board);
this.A4 = new field('fieldA4', 'white', 'A', '4', null, board);
this.B4 = new field('fieldA4', 'black', 'B', '4', null, board);
this.C4 = new field('fieldC4', 'white', 'C', '4', null, board);
this.D4 = new field('fieldD4', 'black', 'D', '4', null, board);
this.E4 = new field('fieldE4', 'white', 'E', '4', null, board);
this.F4 = new field('fieldF4', 'black', 'F', '4', null, board);
this.G4 = new field('fieldG4', 'white', 'G', '4', null, board);
this.H4 = new field('fieldH4', 'black', 'H', '4', null, board);
this.A5 = new field('fieldA5', 'black', 'A', '5', null, board);
this.B5 = new field('fieldB5', 'white', 'B', '5', null, board);
this.C5 = new field('fieldC5', 'black', 'C', '5', null, board);
this.D5 = new field('fieldD5', 'white', 'D', '5', null, board);
this.E5 = new field('fieldE5', 'black', 'E', '5', null, board);
this.F5 = new field('fieldF5', 'white', 'F', '5', null, board);
this.G5 = new field('fieldG5', 'black', 'G', '5', null, board);
this.H5 = new field('fieldH5', 'white', 'H', '5', null, board);
this.A6 = new field('fieldA6', 'white', 'A', '6', null, board);
this.B6 = new field('fieldB6', 'black', 'B', '6', null, board);
this.C6 = new field('fieldC6', 'white', 'C', '6', null, board);
this.D6 = new field('fieldD6', 'black', 'D', '6', null, board);
this.E6 = new field('fieldE6', 'white', 'E', '6', null, board);
this.F6 = new field('fieldF6', 'black', 'F', '6', null, board);
this.G6 = new field('fieldG6', 'white', 'G', '6', null, board);
this.H6 = new field('fieldH6', 'black', 'H', '6', null, board);
this.A7 = new field('fieldA7', 'black', 'A', '7', null, board);
this.B7 = new field('fieldB7', 'white', 'B', '7', null, board);
this.C7 = new field('fieldC7', 'black', 'C', '7', null, board);
this.D7 = new field('fieldD7', 'white', 'D', '7', null, board);
this.E7 = new field('fieldE7', 'black', 'E', '7', null, board);
this.F7 = new field('fieldF7', 'white', 'F', '7', null, board);
this.G7 = new field('fieldG7', 'black', 'G', '7', null, board);
this.H7 = new field('fieldH7', 'white', 'H', '7', null, board);
this.A8 = new field('fieldA8', 'white', 'A', '8', null, board);
this.B8 = new field('fieldB8', 'black', 'B', '8', null, board);
this.C8 = new field('fieldC8', 'white', 'C', '8', null, board);
this.D8 = new field('fieldD8', 'black', 'D', '8', null, board);
this.E8 = new field('fieldE8', 'white', 'E', '8', null, board);
this.F8 = new field('fieldF8', 'black', 'F', '8', null, board);
this.G8 = new field('fieldG8', 'white', 'G', '8', null, board);
this.H8 = new field('fieldH8', 'black', 'H', '8', null, board);
}
function board() {
this.moves = new move_collection(this);
this.figures = new figure_collection(this);
this.fields = new field_collection(this);
this.init = init;
this.last_move = null;
// Обновляет позицию
this.refresh_moves = function() {
// Ajax запрос к серверу
new Ajax.Request(moves_url, {
method: 'get',
onSuccess: function(transport) {
all_moves = transport.responseText;
trace('ajax: ' + all_moves);
}
});
trace('call => parse_moves(' + all_moves + ')')
function existsWhite(move) {
return getWhiteMove(move) != "******";
}
function existsBlack(move) {
return getBlackMove(move) != "******";
}
function getWhiteMove(move) {
return move.substring(0,6);
}
function getWhiteTime(move) {
return move.substring(13, 19);
}
function getBlackMove(move) {
return move.substring(6,12);
}
function getBlackTime(move) {
return move.substring(20, 26);
}
function getFrom(color, move) {
}
function getTo(color, move) {
}
function isShortCastling(color, move) {
}
function isLongCastling(color, move) {
}
moves_split = all_moves.split('|');
moves_strip = new Array();
for(i = 0; i < moves_split.length; i++) {
if(moves_split[i] != "") {
moves_strip.push(moves_split[i]);
trace('split: ' + moves_split[i]);
}
}
var number = moves_strip.length;
trace('number = ' + number);
var current_move = this.moves.get_current_move();
trace('current_move = ' + current_move);
var current_number = current_move != null ? current_move.number : 0;
trace('current_number = ' + current_number);
if(number == current_number) {
if((current_move.color == 'white') && existsBlack(moves_strip[number - 1])) {
var move_annotation = getBlackMove(moves_strip[number - 1]);
var move_time = getBlackTime(moves_strip[number - 1]);
var fieldFrom = getFrom('black', move_annotation);
var fieldTo = getTo('black', move_annotation);
var move = new move(number, 'black', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('black', move_annotation), isLongCastling('black', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
}
if(number > current_number){
for(iMove = current_move; iMove < number; iMove++) {
var move_annotation = getWhiteMove(moves_strip[number - 1]);
if(existsWhite(move_annotation)) {
var move_time = getWhiteTime(moves_strip[number - 1]);
var fieldFrom = getFrom('white', move_annotation);
var fieldTo = getTo('white', move_annotation);
var move = new move(iMove + 1, 'white', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('white', move_annotation), isLongCastling('white', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
move_annotation = getBlackMove(moves_strip[number - 1]);
if(existsBlack(move_annotation)) {
var move_time = getBlackTime(moves_strip[number - 1]);
var fieldFrom = getFrom('black', move_annotation);
var fieldTo = getTo('black', move_annotation);
var move = new move(iMove + 1, 'black', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('black', move_annotation), isLongCastling('black', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
}
}
}
this.refresh_figures = refresh_figures;
this.go_begin = go_begin;
this.go_end = go_end;
this.go_next = go_next;
this.go_preview = go_preview;
this.go_custom = go_custom;
this.repaint = function() {
}
// Парсит данные пришедшие от сервера
this.parse_moves = function() {
var moves = this.all_moves;
trace('call => parse_moves(' + moves + ')')
function existsWhite(move) {
return getWhiteMove(move) != "******";
}
function existsBlack(move) {
return getBlackMove(move) != "******";
}
function getWhiteMove(move) {
return move.substring(0,6);
}
function getWhiteTime(move) {
return move.substring(13, 19);
}
function getBlackMove(move) {
return move.substring(6,12);
}
function getBlackTime(move) {
return move.substring(20, 26);
}
function getFrom(color, move) {
}
function getTo(color, move) {
}
function isShortCastling(color, move) {
}
function isLongCastling(color, move) {
}
moves_split = moves.split('|');
moves_strip = new Array();
for(i = 0; i < moves_split.length; i++) {
if(moves_split[i] != null) {
moves_strip.push(moves_split[i]);
}
}
var number = moves_strip.length;
var current_move = this.moves.get_current_move;
var current_number = current_move != null ? current_move.number : 0;
if(number == current_number) {
if((current_move.color == 'white') && existsBlack(moves_strip[number - 1])) {
var move_annotation = getBlackMove(moves_strip[number - 1]);
var move_time = getBlackTime(moves_strip[number - 1]);
var fieldFrom = getFrom('black', move_annotation);
var fieldTo = getTo('black', move_annotation);
var move = new move(number, 'black', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('black', move_annotation), isLongCastling('black', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
}
if(number > current_number){
for(iMove = current_move; iMove < number; iMove++) {
var move_annotation = getWhiteMove(moves_strip[number - 1]);
if(existsWhite(move_annotation)) {
var move_time = getWhiteTime(moves_strip[number - 1]);
var fieldFrom = getFrom('white', move_annotation);
var fieldTo = getTo('white', move_annotation);
var move = new move(iMove + 1, 'white', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('white', move_annotation), isLongCastling('white', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
move_annotation = getBlackMove(moves_strip[number - 1]);
if(existsBlack(move_annotation)) {
var move_time = getBlackTime(moves_strip[number - 1]);
var fieldFrom = getFrom('black', move_annotation);
var fieldTo = getTo('black', move_annotation);
var move = new move(iMove + 1, 'black', fieldFrom, fieldTo, fieldFrom.figure, fieldTo.figure, isShortCastling('black', move_annotation), isLongCastling('black', move_annotation), current_move, null, this, move_time);
this.moves.add_move(move);
}
}
}
}
// Настройки
this.all_moves = "";
this.moves_delay = 3;
this.moves_url = '/main/game_moves/1';
this.figures_delay = 2;
}
// Инициализация доски
function init() {
trace('call => init()');
// Расставляем шахматы в начальную позицию
// белые пешки
this.figures.wpA.set_field(this.fields.A2);
this.figures.wpB.set_field(this.fields.B2);
this.figures.wpC.set_field(this.fields.C2);
this.figures.wpD.set_field(this.fields.D2);
this.figures.wpE.set_field(this.fields.E2);
this.figures.wpF.set_field(this.fields.F2);
this.figures.wpG.set_field(this.fields.G2);
this.figures.wpH.set_field(this.fields.H2);
// белые фигуры
this.figures.wrA.set_field(this.fields.A1);
this.figures.wrH.set_field(this.fields.H1);
this.figures.whB.set_field(this.fields.B1);
this.figures.whG.set_field(this.fields.G1);
this.figures.wbC.set_field(this.fields.C1);
this.figures.wbF.set_field(this.fields.F1);
this.figures.wq.set_field(this.fields.D1);
this.figures.wk.set_field(this.fields.E1);
// черные пешки
this.figures.bpA.set_field(this.fields.A7);
this.figures.bpB.set_field(this.fields.B7);
this.figures.bpC.set_field(this.fields.C7);
this.figures.bpD.set_field(this.fields.D7);
this.figures.bpE.set_field(this.fields.E7);
this.figures.bpF.set_field(this.fields.F7);
this.figures.bpG.set_field(this.fields.G7);
this.figures.bpH.set_field(this.fields.H7);
// черные фигуры
this.figures.brA.set_field(this.fields.A8);
this.figures.brH.set_field(this.fields.H8);
this.figures.bhB.set_field(this.fields.B8);
this.figures.bhG.set_field(this.fields.G8);
this.figures.bbC.set_field(this.fields.C8);
this.figures.bbF.set_field(this.fields.F8);
this.figures.bq.set_field(this.fields.D8);
this.figures.bk.set_field(this.fields.E8);
// Создаем Ajax опрашиватель сервера
new PeriodicalExecuter(this.refresh_moves, this.moves_delay);
new PeriodicalExecuter(this.refresh_figures, this.figures_delay);
}
// Перерисовка позиции (делает один ход)
function refresh_figures() {
//trace('call => refresh_figures');
if(this.exists_move) {
this.current_move = this.moves.get_current_move();
this.current_move.forward();
}
}
// Перейти к началу
function go_begin() {
}
// Перейти к концу
function go_end() {
}
// Следующий ход
function go_next() {
}
// Предыдущий ход
function go_preview() {
}
// Перейти к произвольному ходу
function go_custom(number, color) {
}
// сделать ход
function do_move(from_field, to_field) {
}
// Возвращает поле
function get_field(vertical, horizontal) {
}
// Установить фигуру на поле
function set_field(field_to_set) {
this.last_field = field_to_set;
field_to_set.figure = this;
field_to_set.repaint();
}
// Возвращает ход по номеру и цвету
function get_move(number, color) {
}
// Возвращает текуший ход
function get_current_move() {
return this.current_move;
}
// Возвращает true если есть ход который нужно совершить
function exists_move() {
}
function repaint() {
$(this.id).innerHTML = '';
if(this.figure != null) {
$(this.id).appendChild(this.figure.img);
}
}
function reload() {
this.img.src = images + this.color[0] + this.type[0] + '.gif';
//trace('reload figure [' + this.id + '].src = \"' + this.img.src + '\"');
}
// Ход вперед !! предыдущую фигуру удалить
function forward(){
if(this.to_field.figure != null) {
}
this.figure.do_move(this.from_field, this.to_field);
}
// Ход назад
function backward() {
this.figure.do_move(this.to_field, this.from_field);
this.alive_figure.set_field(this.to_field);
}
function trace(message) {
$("debug").innerHTML += message + '<br />';
}
window.onload=function() {
// Запуск
var main_board = new board();
main_board.init();
// setBeginingPosition();
// refreshGame();
// new PeriodicalExecuter(refreshGame, periodicalDelay);
// new PeriodicalExecuter(refreshBoard, 1);
}
Приложение Г
Листинг программы-регистратора шахматных партий
rdgtChess.java
---
public class rdgtChess implements Runnable
static boolean debug = false;
String comport = "COM1";
public static void main(String[] args) {
rdgtChess t;
if(args.length > 0)
t = new rdgtChess(args[0]);
else
t = new rdgtChess();
}
public rdgtChess() {
(new Thread(this)).start();
}
public rdgtChess(String comport) {
this.comport = comport;
(new Thread(this)).start();
}
// Destructor
public void finalize()
{
rdgtMysql.disconnect();
}
// This is the main loop. It samples all boards and tries at regular intervals
// to find new boards and to mark non-answering boards as, well, non-answering.
Это головная часть. Она опрашивает все доски с регулярным интервалом времени,
чтобы найти новые доски и отметить неотвечающие доски как неотвечающие
public void run() {
rdgtController c = new rdgtController();
if (c.connect(comport) == false) return;
System.out.println(rdgtMysql.connect());
int i = 0;
while (true) {
if ((i==0) || (c.db.count_alive()==0)) {
while (c.find_all_boards()==0) {} c.dump_all_active_boards();
i = 15;
} else {
try {Thread.sleep(1000);} catch(Throwable t) {}}
c.poll_all_active_boards();
i--;
}
}
}
rdgtChessboard.java
---
class rdgtChessboard {
Integer address;
rdgtHistory history = new rdgtHistory(this);
rdgtSnapshot snapshot = new rdgtSnapshot(this);
rdgtFenhax myFenhax = new rdgtFenhax();
boolean alive;
boolean dumped;
boolean updated;
rdgtDatabase db;
rdgtChessBoardForm board = null;
public rdgtChessboard(Integer _address, rdgtDatabase _db) {
address = _address;
db = _db;
alive = true;
dumped = false;
updated = false;
update_html();
board = new rdgtChessBoardForm();
new Thread(new Runnable() {
public void run() {
board.setVisible(true);
}
}).start();
}
rdgtSnapshot get_snapshot() {
return snapshot;
}
int get_address() {
return address.intValue();
}
public void print_position() {
board.printPosition(snapshot.debugprint());
board.printClock(snapshot.debugprint_clock());
}
String print_figure(int figure) {
if(figure == rdgtProtocol.EMPTY) {
return " ";
} else if (figure == rdgtProtocol.WPAWN) {
return "P";
} else if(figure == rdgtProtocol.WROOK) {
return "R";
} else if(figure == rdgtProtocol.WKNIGHT) {
return "N";
} else if(figure == rdgtProtocol.WBISHOP) {
return "B";
} else if(figure == rdgtProtocol.WQUEEN) {
return "Q";
} else if(figure == rdgtProtocol.WKING) {
return "K";
} else if (figure == rdgtProtocol.BPAWN) {
return "p";
} else if(figure == rdgtProtocol.BROOK) {
return "r";
} else if(figure == rdgtProtocol.BKNIGHT) {
return "n";
} else if(figure == rdgtProtocol.BBISHOP) {
return "b";
} else if(figure == rdgtProtocol.BQUEEN) {
return "q";
} else if(figure == rdgtProtocol.BKING) {
return "k";
} else {
return " ";
}
}
void set_alive(boolean x) {
alive = x;
update_html();
}
void set_dumped(boolean x) {
dumped = x;
}
void set_updated(boolean x) {
updated = x;
history.append(snapshot);
}
boolean get_alive() {
return alive;
}
boolean get_dumped() {
return dumped;
}
boolean get_updated() {
return updated;
}
void set_clockdata(boolean running, boolean batteryLow, boolean frontViewLeftSideHigh, boolean blacksTurn, boolean whitesTurn, int secW, int secB) {
snapshot.set_clockdata(running, batteryLow, frontViewLeftSideHigh, blacksTurn, whitesTurn, secW, secB);
snapshot.debugprint_clock();
}
void update_html() {
rdgtMysql.update_snapshot(snapshot);
String fen = rdgtMysql.snapshot2fen(snapshot);
myFenhax.add(fen);
rdgtMysql.update_moves(rdgtFenhax.getMoves(true, false), rdgtFenhax.getMoves(true, true), address.intValue());
}
void set_emptyboard() {
snapshot.set_emptyboard();
history.append(snapshot);
}
void set_boarddump(int[] all64, int startpos) {
snapshot.set_boarddump(all64, startpos);
dumped = true;
history.append(snapshot);
}
void set_fieldupdate(int piece, int pos) {
snapshot.set_fieldupdate(piece, pos);
updated = true;
history.append(snapshot);
}
}
rdgtConfig.java
---
class rdgtConfig {
String getDbServer() { return server; }
String getDbUser() { return user; }
String getDbPass() { return pass; }
String getDbBase() { return dbase; }
boolean useDbServer() { return mysql; }
boolean usePgnWriter() { return pgn; }
String getPgnFileName() { return pgnfile; }
String server= "localhost";
String user= "root";
String pass= "zar1562";
String dbase= "rdgt_development";
boolean mysql = true;
boolean pgn = false;
String pgnfile = "default.pgn";
}
rdgtController.java
---
class rdgtController extends rdgtProtocol {
rdgtDatabase db;
rdgtInterpreter ipr;
rdgtReceiver rec;
rdgtSerialport ser;
rdgtSender snd;
public rdgtController() {
db = new rdgtDatabase();
ipr = new rdgtInterpreter(db);
rec = new rdgtReceiver(ipr);
ser = new rdgtSerialport(rec);
snd = new rdgtSender(ser);
}
boolean connect(String comport) {
if (ser.open(comport)==false) {
System.out.println("Could not open "+comport);
return false;
}
System.out.println("COM port opened: "+comport);
return true;
}
int find_all_boards() {
System.out.println("Scanning for boards...");
db.unalive_all();
int alive = 0;
while (true) {
try {Thread.sleep(300);} catch(Throwable t) {}
snd.send(DGT_BUS_PING, 0);
try {Thread.sleep(1100);} catch(Throwable t) {}
int alivenow = db.count_alive();
if (alivenow == alive) break;
alive = alivenow;
for (Enumeration e = db.get_boards() ; e.hasMoreElements() ;) {
rdgtChessboard b = (rdgtChessboard)(e.nextElement());
if (b.get_alive()==true) {
snd.send(DGT_BUS_IGNORE_NEXT_BUS_PING, b.get_address());
}
}
}
System.out.println("Scanning completed, found "+Integer.toString(alive)+" boards.\n");
return alive;
}
void dump_all_active_boards() {
for (Enumeration e = db.get_boards() ; e.hasMoreElements() ;) {
rdgtChessboard b = (rdgtChessboard)(e.nextElement());
if (b.get_alive()==true) {
b.set_dumped(false);
for (int i=0; i<3; i++) { if (b.get_dumped()==true) break;
snd.send(DGT_BUS_SEND_BRD, b.get_address());
try {Thread.sleep(200);} catch(Throwable t) {}
}
if (b.get_dumped()==false) {
System.out.println("Board "+Integer.toString(b.get_address())+" does not reply to dump_board.");
b.set_alive(false);
}
}
}
}
void poll_all_active_boards() {
int TIMEOUT = 100;
for (Enumeration e = db.get_boards() ; e.hasMoreElements() ;) {
rdgtChessboard b = (rdgtChessboard)(e.nextElement());
if (b.get_alive()==true) {
snd.send(DGT_BUS_SEND_CLK, b.get_address());
try {Thread.sleep(TIMEOUT);} catch(Throwable t) {}
b.set_updated(false);
snd.send(DGT_BUS_SEND_CHANGES, b.get_address());
try {Thread.sleep(TIMEOUT);} catch(Throwable t) {}
for (int i=0; i<2; i=i+1) {
if (b.get_updated()==true) break;
snd.send(DGT_BUS_REPEAT_CHANGES, b.get_address());
try {Thread.sleep(TIMEOUT);} catch(Throwable t) {}}
if (b.get_updated()==false) {
System.out.println("Board "+Integer.toString(b.get_address())+" does not reply anymore.");
b.set_alive(false);
} else {
b.print_position();
}
}
}
}
}
rdgtDatabase.java
---
class rdgtDatabase {
Hashtable boards;
public rdgtDatabase() {
boards = new Hashtable();
}
rdgtChessboard get_board(int address) {
Integer _address = new Integer(address);
rdgtChessboard b = (rdgtChessboard)(boards.get(_address));
if (b==null) {
System.out.println("New board found: ID="+_address.toString());
b = new rdgtChessboard(_address, this);
boards.put(_address, b);
}
return b;
}
int get_boardcount() {
return boards.size();
}
Enumeration get_boards() {
return boards.elements();
}
void unalive_all() {
for (Enumeration e = boards.elements() ; e.hasMoreElements() ;) {
((rdgtChessboard)(e.nextElement())).set_alive(false);
}
}
int count_alive() {
int x = 0;
for (Enumeration e = boards.elements() ; e.hasMoreElements() ;) {
if (((rdgtChessboard)(e.nextElement())).get_alive()==true) x++;
}
return x;
}
}
rdgtFenboard.java
---
class rdgtFenboard {
int[] itsBoard;
String itsFen;
public rdgtFenboard(){
itsBoard = new int[64];
for(int i=0;i<64;i++)
itsBoard[i]='.';
itsFen="";
}
public rdgtFenboard(String fen){ setBoard(fen); }
public rdgtFenboard(int[] board) { setBoard(board); }
public boolean setBoard(String fen){
if(!validateFen(fen))
return false;
itsBoard=fen2board(fen);
itsFen=fen;
return true;
}
public int getPieceAt(int x, int y){
if(x<0 || x>7 || y<0 || y>7) return 0;
return itsBoard[y*8+x];
}
public boolean setBoard(int[] board){
if(board.length != 64)
return false;
itsBoard=board;
return true;
}
public void print(){
printBoard(itsBoard);
}
public int[] getBoard() { return itsBoard; }
public rdgtFenboard mask(rdgtFenboard b){
rdgtFenboard output;
output=new rdgtFenboard(mask(getBoard(),b.getBoard()));
return output;
}
public int diffCount(rdgtFenboard b){
rdgtFenboard m = mask(b);
int[] table=m.getBoard();
int output=0;
for(int i=0;i<64;i++){
if(table[i]!='.')
output++;
}
return output;
}
int[] fen2board(String aFen){
int[] board = new int[64];
int square=0;
int chr=0;
while(square<64){
char c = aFen.charAt(chr);
if(c=='r'||c=='R'||c=='n'||c=='N'||c=='b'||c=='B'||c=='q'||c=='Q'||c=='k'||c=='K'||c=='p'||c=='P'){
board[square]=c;
square++;
}
if(c>='1' && c<='8'){
for(int i=0;i<c-'1'+1;i++){
board[square]='.';
square++;
}
}
chr++;
}
return board;
Подобные документы
Модель этапа пост-архитектуры. Предварительная оценка программного проекта на основе LOC-метрик. Расчет затрат на разработку ПО. Стоимость, длительность разработки проекта на основе модели этапа пост-архитектуры конструктивной модели стоимости СОСОМО II.
курсовая работа [89,9 K], добавлен 29.09.2009Требования к функциям и задачам, выполняемым системой "Подбор кредита ОАО "Россельхозбанк". Проектирование архитектуры программного продукта. Структурная схема программного продукта. Описание компонент программного обеспечения. План менеджмента проекта.
курсовая работа [684,0 K], добавлен 03.05.2015Характеристика программного продукта и стадий разработки. Расчет затрат на разработку и договорной цены, эксплуатационных расходов, связанных с использованием нового программного продукта. Оценка конкурентоспособности. Изучение, оценка рыночного спроса.
курсовая работа [139,0 K], добавлен 22.09.2008Информационное обеспечение задачи автоматизации учета. Программное обеспечение задачи автоматизации учета. Расчет технико-экономической эффективности программного продукта по учету пластиковых карт. Расчет затрат на разработку программного модуля.
дипломная работа [2,1 M], добавлен 10.02.2018Реализация программного средства "Действия над матрицами". Разработка кода программного продукта на основе готовой спецификации на уровне модуля. Использование инструментальных средств на этапе отладки программного модуля. Выбор стратегии тестирования.
отчет по практике [296,1 K], добавлен 19.04.2015Разработка программного обеспечения для микропроцессорных систем МК51, интерфейсы в системах связи, основы асинхронной связи. Этапы решения задачи на ЭВМ, принципы тестирования программ и их отладка. Расчет затрат на разработку программного продукта.
дипломная работа [270,6 K], добавлен 19.06.2010Расчет издержек предприятия на разработку программного продукта и экономической эффективности от его внедрения. Топология физических связей и структуризация сети. Характеристика программного обеспечения. Средства автоматизации, описание алгоритма задачи.
дипломная работа [867,6 K], добавлен 05.11.2015Создание программного продукта для учета и просмотра информации о товаре, поступающем на склад организации ООО "Риф" на языках программирования PHP и MySQL. Руководство по работе с программой. Расчет экономической эффективности разработанного проекта.
дипломная работа [549,9 K], добавлен 21.06.2011Анализ существующего программного обеспечения. Этапы создания проекта. Концептуальное, логическое и физическое проектирование базы данных. Структура программного продукта. Руководство программиста и оператора. Тестирование программного продукта.
курсовая работа [586,4 K], добавлен 26.06.2015Изучение основных видов угроз программного обеспечения. Выявление наиболее эффективных средств и методов защиты программного обеспечения. Анализ их достоинств и недостатков. Описания особенностей лицензирования и патентования программного обеспечения.
курсовая работа [67,9 K], добавлен 29.05.2013