Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 138130a
Showing
107 changed files
with
5,313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2009-2010 Thibault Duplessis | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
This Diem plugin is about Chess game. | ||
|
||
Provides a graphical HTML/CSS/JAVASCRIPT client, and an Artificial Intelligence server. | ||
|
||
It allows to play against a distant friend or an aggressive AI. | ||
|
||
Install a full featured Chess game on your Diem project in seconds. | ||
|
||
Can also act as a Chess AI webservice. | ||
|
||
Heavily unit tested ( currently 427 unit tests ) | ||
|
||
Will only work with Diem 5.0 installed. This plugin uses dependency injection service container and is fully extensible. Please send a request if you want to help improve or translate it. | ||
|
||
Documentation: http://diem-project.org/plugins/dmchessplugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
js: | ||
|
||
dmChessPlugin: | ||
|
||
ctrl: ctrl | ||
game: game | ||
|
||
css: | ||
|
||
dmChessPlugin: | ||
|
||
board: board | ||
table: table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Project: | ||
|
||
Chess: | ||
|
||
dmChessGame: | ||
name: Chess Game | ||
actions: | ||
play: | ||
|
||
dmChessPlayer: | ||
parent: dmChessGame | ||
name: Chess Player | ||
front: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
parameters: | ||
|
||
dm_chess_board.class: dmChessBoard | ||
dm_chess_board.options: | ||
square_class: dmChessSquare | ||
|
||
dm_chess_event_log.class: dmChessEventLog | ||
|
||
dm_chess_asset_loader.class: dmChessAssetLoader | ||
|
||
dm_chess_javascript_config.class: dmChessJavascriptConfig | ||
|
||
dm_chess_piece_filter.class: dmChessPieceFilter | ||
|
||
dm_chess_ai.class: dmChessAi | ||
dm_chess_ai.options: | ||
driver: web # can be "stupid" or "web" or "crafty" | ||
level: 3 | ||
|
||
dm_chess_ai_driver_stupid.class: dmChessAiDriverStupid | ||
|
||
dm_chess_ai_driver_web.class: dmChessAiDriverWeb | ||
dm_chess_ai_driver_web.options: | ||
url: http://chess.diem-project.org/+/dmChessAiServer/play | ||
level: 3 | ||
|
||
dm_chess_ai_driver_crafty.class: dmChessAiDriverCrafty | ||
dm_chess_ai_driver_crafty.options: | ||
level: 3 | ||
|
||
dm_chess_ai_server.class: dmChessAiServer | ||
dm_chess_ai_server.options: | ||
enabled: false | ||
|
||
dm_chess_crafty.class: dmChessCrafty | ||
dm_chess_crafty.options: | ||
path: /usr/games/crafty | ||
level: 3 | ||
|
||
dm_chess_forsythe.class: dmChessForsytheNotation | ||
|
||
services: | ||
|
||
dm_chess_board: | ||
class: %dm_chess_board.class% | ||
shared: false | ||
arguments: [ %dm_chess.game%, %dm_chess_board.options% ] | ||
|
||
dm_chess_event_log: | ||
class: %dm_chess_event_log.class% | ||
shared: true | ||
arguments: [ @dispatcher ] | ||
|
||
dm_chess_asset_loader: | ||
class: %dm_chess_asset_loader.class% | ||
shared: false | ||
arguments: [ @response ] | ||
|
||
dm_chess_javascript_config: | ||
class: %dm_chess_javascript_config.class% | ||
shared: false | ||
arguments: [ @response, @helper, @i18n, %dm_chess.player% ] | ||
|
||
dm_chess_piece_filter: | ||
class: %dm_chess_piece_filter.class% | ||
shared: true | ||
arguments: [ ] | ||
|
||
dm_chess_forsythe: | ||
class: %dm_chess_forsythe.class% | ||
shared: true | ||
arguments: [ ] | ||
|
||
dm_chess_ai: | ||
class: %dm_chess_ai.class% | ||
shared: false | ||
arguments: [ @service_container, %dm_chess_ai.options% ] | ||
|
||
dm_chess_ai_driver_stupid: | ||
class: %dm_chess_ai_driver_stupid.class% | ||
shared: false | ||
arguments: [ %dm_chess.player% ] | ||
|
||
dm_chess_ai_driver_crafty: | ||
class: %dm_chess_ai_driver_crafty.class% | ||
shared: false | ||
arguments: [ %dm_chess.player%, @service_container, %dm_chess_ai_driver_crafty.options% ] | ||
|
||
dm_chess_ai_driver_web: | ||
class: %dm_chess_ai_driver_web.class% | ||
shared: false | ||
arguments: [ %dm_chess.player%, @service_container, %dm_chess_ai_driver_web.options% ] | ||
|
||
dm_chess_ai_server: | ||
class: %dm_chess_ai_server.class% | ||
shared: false | ||
arguments: [ @service_container, %dm_chess_ai_server.options% ] | ||
|
||
dm_chess_crafty: | ||
class: %dm_chess_crafty.class% | ||
shared: false | ||
arguments: [ @service_container, %dm_chess_crafty.options% ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
class dmChessPluginConfiguration extends sfPluginConfiguration | ||
{ | ||
protected | ||
$eventLog; | ||
|
||
/** | ||
* @see sfPluginConfiguration | ||
*/ | ||
public function initialize() | ||
{ | ||
$this->dispatcher->connect('dm.context.loaded', array($this, 'listenToContextLoadedEvent')); | ||
} | ||
|
||
public function listenToContextLoadedEvent(sfEvent $e) | ||
{ | ||
$this->eventLog = $e->getSubject()->get('event_log'); | ||
|
||
$this->eventLog->setOption('ignore_models', array_merge($this->eventLog->getOption('ignore_models'), array( | ||
'DmChessGame', | ||
'DmChessPlayer' | ||
))); | ||
|
||
$this->dispatcher->connect('dm.chess.piece_move', array($this, 'listenToPieceMoveEvent')); | ||
|
||
$this->dispatcher->connect('dm.chess_server.play', array($this, 'listenToServerPlayEvent')); | ||
} | ||
|
||
public function listenToPieceMoveEvent(dmChessPieceMoveEvent $event) | ||
{ | ||
$piece = $event->getSubject(); | ||
$player = $piece->get('Player'); | ||
$game = $player->get('Game'); | ||
|
||
$this->eventLog->log(array( | ||
'server' => $_SERVER, | ||
'action' => 'chess', | ||
'type' => 'chess move', | ||
'subject' => sprintf('(%d.%d) %s %s %s %s %s', | ||
$game->get('id'), | ||
$game->get('turns'), | ||
$player->get('color'), | ||
$player->get('is_ai') ? 'A.I. level '.$player->get('ai_level') : 'Human', | ||
ucfirst($piece->get('type')), | ||
ucfirst($event['from']->getHumanPos()), | ||
ucfirst($event['to']->getHumanPos()) | ||
) | ||
)); | ||
} | ||
|
||
public function listenToServerPlayEvent(sfEvent $event) | ||
{ | ||
$this->eventLog->log(array( | ||
'server' => $_SERVER, | ||
'action' => 'chess', | ||
'type' => 'chess web service', | ||
'subject' => sprintf('A.I. level %s in %.2f s', $event['level'], $event['time']) | ||
)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
DmChessGame: | ||
actAs: | ||
Timestampable: | ||
columns: | ||
code: { type: string(8), notnull: true, unique: true } | ||
is_started: { type: boolean, notnull: true, default: false } | ||
is_finished: { type: boolean, notnull: true, default: false } | ||
turns: { type: integer(2), notnull: true, default: 0 } | ||
|
||
DmChessPlayer: | ||
columns: | ||
code: { type: string(8), notnull: true, unique: true } | ||
is_creator: { type: boolean, notnull: true, default: false } | ||
is_winner: { type: boolean, notnull: true, default: false } | ||
is_ai: { type: boolean, notnull: true, default: false } | ||
ai_level: { type: integer(1) } | ||
game_id: { type: integer, notnull: true } | ||
color: { type: enum, notnull: true, values: [white, black] } | ||
events: { type: string(255) } | ||
relations: | ||
Game: | ||
local: game_id | ||
class: DmChessGame | ||
foreignAlias: Players | ||
onDelete: CASCADE | ||
|
||
DmChessPiece: | ||
options: | ||
symfony: { form: false, filter: false } | ||
columns: | ||
player_id: { type: integer, notnull: true } | ||
type: { type: enum, notnull: true, values: [king, queen, rook, knight, bishop, pawn] } | ||
x: { type: integer(1) } | ||
y: { type: integer(1) } | ||
is_dead: { type: integer(2), notnull: true, default: 0 } | ||
first_move: { type: integer(2), notnull: true, default: -1 } | ||
relations: | ||
Player: | ||
local: player_id | ||
class: DmChessPlayer | ||
foreignAlias: Pieces | ||
onDelete: CASCADE | ||
|
||
DmChessKing: | ||
options: | ||
symfony: { form: false, filter: false } | ||
inheritance: | ||
type: column_aggregation | ||
extends: DmChessPiece | ||
keyField: type | ||
keyValue: king | ||
|
||
DmChessQueen: | ||
options: | ||
symfony: { form: false, filter: false } | ||
inheritance: | ||
type: column_aggregation | ||
extends: DmChessPiece | ||
keyField: type | ||
keyValue: queen | ||
|
||
DmChessRook: | ||
options: | ||
symfony: { form: false, filter: false } | ||
inheritance: | ||
type: column_aggregation | ||
extends: DmChessPiece | ||
keyField: type | ||
keyValue: rook | ||
|
||
DmChessKnight: | ||
options: | ||
symfony: { form: false, filter: false } | ||
inheritance: | ||
type: column_aggregation | ||
extends: DmChessPiece | ||
keyField: type | ||
keyValue: knight | ||
|
||
DmChessBishop: | ||
options: | ||
symfony: { form: false, filter: false } | ||
inheritance: | ||
type: column_aggregation | ||
extends: DmChessPiece | ||
keyField: type | ||
keyValue: bishop | ||
|
||
DmChessPawn: | ||
options: | ||
symfony: { form: false, filter: false } | ||
inheritance: | ||
type: column_aggregation | ||
extends: DmChessPiece | ||
keyField: type | ||
keyValue: pawn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"Game over": "Partie terminée" | ||
"%1% is victorious": "%1% est victorieux" | ||
"Draw": "Egalité" | ||
"Start a new game": "Commencer une nouvelle partie" | ||
"To invite someone to play, give this url:": "Pour inviter quelqu'un à jouer, donnez cette url:" | ||
"Or challenge the Artificial Intelligence": "Ou défiez l'intelligence artificielle" | ||
"Your turn": "A vous de jouer" | ||
"Waiting for opponent": "Attente de l'adversaire" | ||
"You just added the chess/game widget. Please reload the page to activate it, and this message will never appear again.": "Vous venez d'ajouter le widget chess/game. Veuillez recharger la page pour l'activer, et ce message n'apparaîtra plus jamais." | ||
"Opponent is Crafty A.I.": "Adversaire: Crafty A.I." | ||
"Human opponent": "Adversaire humain" | ||
"Resign": "Abandonner" | ||
"Resign this game": "Abandonner cette partie" | ||
"To continue later, use this url:": "Pour reprendre la partie plus tard, utilisez cette url:" | ||
"Your browser does not support JavaScript.": "Votre navigateur ne supporte pas JavaScript." | ||
"Creating a new game...": "Création d'une nouvelle partie..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
class dmChessAi extends dmConfigurable | ||
{ | ||
protected | ||
$serviceContainer; | ||
|
||
public function __construct(dmBaseServiceContainer $serviceContainer, array $options = array()) | ||
{ | ||
$this->serviceContainer = $serviceContainer; | ||
|
||
$this->initialize($options); | ||
} | ||
|
||
protected function initialize(array $options) | ||
{ | ||
$this->configure($options); | ||
} | ||
|
||
public function move() | ||
{ | ||
return $this->serviceContainer | ||
->getService('dm_chess_ai_driver_'.$this->getOption('driver')) | ||
->setOption('level', $this->getOption('level')) | ||
->move(); | ||
} | ||
|
||
} |
Oops, something went wrong.