Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
billforsternz committed Nov 16, 2015
2 parents 8e2f11d + d61a02c commit 384dd24
Show file tree
Hide file tree
Showing 56 changed files with 24,126 additions and 4,156 deletions.
11 changes: 9 additions & 2 deletions TarraschVS2010.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1021,18 +1021,22 @@
<ClInclude Include="src\t3\BookDialog.h" />
<ClInclude Include="src\t3\Canvas.h" />
<ClInclude Include="src\t3\CentralWorkSaver.h" />
<ClInclude Include="src\t3\ClipboardDialog.h" />
<ClInclude Include="src\t3\ClockDialog.h" />
<ClInclude Include="src\t3\CompressMoves.h" />
<ClInclude Include="src\t3\CreateDatabaseDialog.h" />
<ClInclude Include="src\t3\CtrlBox.h" />
<ClInclude Include="src\t3\CtrlBox2.h" />
<ClInclude Include="src\t3\CtrlBoxBookMoves.h" />
<ClInclude Include="src\t3\CtrlChessTxt.h" />
<ClInclude Include="src\t3\Database.h" />
<ClInclude Include="src\t3\DbDialog.h" />
<ClInclude Include="src\t3\DbDocument.h" />
<ClInclude Include="src\t3\DbMaintenance.h" />
<ClInclude Include="src\t3\DbPrimitives.h" />
<ClInclude Include="src\t3\DebugPrintf.h" />
<ClInclude Include="src\t3\EngineDialog.h" />
<ClInclude Include="src\t3\GameBase.h" />
<ClInclude Include="src\t3\GameClock.h" />
<ClInclude Include="src\t3\GameClockHalf.h" />
<ClInclude Include="src\t3\GameDetails.h" />
Expand All @@ -1043,7 +1047,6 @@
<ClInclude Include="src\t3\GamePrefixDialog.h" />
<ClInclude Include="src\t3\GamesCache.h" />
<ClInclude Include="src\t3\GamesDialog.h" />
<ClInclude Include="src\t3\GameSkeleton.h" />
<ClInclude Include="src\t3\GameState.h" />
<ClInclude Include="src\t3\GameView.h" />
<ClInclude Include="src\t3\GeneralDialog.h" />
Expand All @@ -1057,7 +1060,9 @@
<ClInclude Include="src\t3\MoveTree.h" />
<ClInclude Include="src\t3\NavigationKey.h" />
<ClInclude Include="src\t3\Objects.h" />
<ClInclude Include="src\t3\PackedGame.h" />
<ClInclude Include="src\t3\PgnDialog.h" />
<ClInclude Include="src\t3\PgnDocument.h" />
<ClInclude Include="src\t3\PgnFiles.h" />
<ClInclude Include="src\t3\PgnRead.h" />
<ClInclude Include="src\t3\PlayerDialog.h" />
Expand All @@ -1084,8 +1089,10 @@
<ClCompile Include="src\t3\BookDialog.cpp" />
<ClCompile Include="src\t3\Canvas.cpp" />
<ClCompile Include="src\t3\CentralWorkSaver.cpp" />
<ClCompile Include="src\t3\ClipboardDialog.cpp" />
<ClCompile Include="src\t3\ClockDialog.cpp" />
<ClCompile Include="src\t3\CompressMoves.cpp" />
<ClCompile Include="src\t3\CreateDatabaseDialog.cpp" />
<ClCompile Include="src\t3\CtrlBox.cpp" />
<ClCompile Include="src\t3\CtrlBox2.cpp" />
<ClCompile Include="src\t3\CtrlBoxBookMoves.cpp" />
Expand All @@ -1104,7 +1111,6 @@
<ClCompile Include="src\t3\GamePrefixDialog.cpp" />
<ClCompile Include="src\t3\GamesCache.cpp" />
<ClCompile Include="src\t3\GamesDialog.cpp" />
<ClCompile Include="src\t3\GameSkeleton.cpp" />
<ClCompile Include="src\t3\GameView.cpp" />
<ClCompile Include="src\t3\GeneralDialog.cpp" />
<ClCompile Include="src\t3\GraphicBoard.cpp" />
Expand All @@ -1116,6 +1122,7 @@
<ClCompile Include="src\t3\MaintenanceDialog.cpp" />
<ClCompile Include="src\t3\MiniBoard.cpp" />
<ClCompile Include="src\t3\MoveTree.cpp" />
<ClCompile Include="src\t3\PackedGame.cpp" />
<ClCompile Include="src\t3\PgnDialog.cpp" />
<ClCompile Include="src\t3\PgnFiles.cpp" />
<ClCompile Include="src\t3\PgnRead.cpp" />
Expand Down
1,961 changes: 1,961 additions & 0 deletions notes.txt

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions src/t3/Appdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ enum
ID_OPTIONS_TRAINING,
ID_OPTIONS_GENERAL,
ID_OPTIONS_RESET,
ID_OPTIONS_MAINTENANCE,
ID_FILE_CURRENT,
ID_FILE_DATABASE,
ID_FILE_SESSION,
ID_FILE_CLIPBOARD,
ID_DATABASE_SEARCH,
ID_DATABASE_SHOW_ALL,
ID_DATABASE_PLAYERS,
ID_DATABASE_SELECT,
ID_DATABASE_CREATE,
ID_DATABASE_APPEND,
ID_DATABASE_MAINTENANCE,
ID_GAMES_CURRENT,
ID_GAMES_DATABASE,
ID_GAMES_SESSION,
ID_GAMES_CLIPBOARD,
ID_EDIT_GAME_DETAILS,
ID_EDIT_GAME_PREFIX,
ID_EDIT_PROMOTE,
Expand Down
33 changes: 29 additions & 4 deletions src/t3/CentralWorkSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool CentralWorkSaver::TestGameInFile()
for( unsigned int i=0; i<gc->gds.size(); i++ )
{
MagicBase *ptr = gc->gds[i].get();
if( ptr && ptr->GetGameBeingEdited()!=0 )
if( ptr && ptr->GetGameBeingEdited()==gd->game_being_edited )
{
in_file = true;
break;
Expand All @@ -88,6 +88,20 @@ bool CentralWorkSaver::TestGameInFile()
return in_file;
}

void CentralWorkSaver::AddTabToFile()
{
//if( !TestGameInFile() )
{
if( gd->r.white == "" ) // if( !game_details_edited )
{
GameDetailsDialog dialog(objs.frame);
if( dialog.Run(*gd) )
objs.gl->GameRedisplayPlayersResult();
}
AddGameToFile();
}
}

// When saving a game, either add it to file ...(see below)
void CentralWorkSaver::AddGameToFile()
{
Expand All @@ -102,9 +116,10 @@ void CentralWorkSaver::AddGameToFile()
// not getting to log or session later (not satisfactory I know - too many flags)
int nbr = gc->gds.size();
gd->game_nbr = nbr + 1;
make_smart_ptr( HoldDocument, new_smart_ptr, *gd ); // smart_ptr event: document->cache
make_smart_ptr( GameDocument, new_smart_ptr, *gd ); // smart_ptr event: document->cache
gc->gds.push_back( std::move(new_smart_ptr) );
objs.gl->file_game_idx = gc->gds.size()-1;
objs.gl->tabs->SetInfile(true);
}

// ...(see above) Or put it back where it came from
Expand Down Expand Up @@ -250,7 +265,7 @@ void CentralWorkSaver::SaveFile( bool prompt, FILE_MODE fm, bool save_as )
objs.gl->file_game_idx = doc.game_nbr;
}
//? gc->Put( GameDocument, doc );
make_smart_ptr( HoldDocument, new_smart_ptr, doc );
make_smart_ptr( GameDocument, new_smart_ptr, doc );
gc->gds.push_back( std::move(new_smart_ptr) );
}
gc->FileSave( gc_clipboard );
Expand Down Expand Up @@ -430,7 +445,7 @@ bool CentralWorkSaver::FileSaveGameAs()
ok = false;
if( ok )
{
wxFileDialog fd( objs.frame, "Select new .pgn file or existing .pgn file", "", "", "*.pgn", wxFD_SAVE ); //|wxFD_CHANGE_DIR );
wxFileDialog fd( objs.frame, "Select .pgn file to create, replace or append to", "", "", "*.pgn", wxFD_SAVE ); //|wxFD_CHANGE_DIR );
wxString dir = objs.repository->nv.m_doc_dir;
fd.SetDirectory(dir);
int answer = fd.ShowModal();
Expand Down Expand Up @@ -466,6 +481,16 @@ bool CentralWorkSaver::FileSaveGameAs()
if( file )
{
fseek(file,0,SEEK_END);
if( append )
{
std::string eol =
#ifdef THC_WINDOWS
"\r\n";
#else
"\n";
#endif
fwrite( eol.c_str(), 1, eol.length(), file );
}
fwrite( head.c_str(), 1, head.length(), file );
fwrite( body.c_str(), 1, body.length(), file );
fclose( file );
Expand Down
1 change: 1 addition & 0 deletions src/t3/CentralWorkSaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CentralWorkSaver
bool FileSaveGameAs();
bool GameNew();
bool PositionNew();
void AddTabToFile();
bool Exit();

private:
Expand Down
40 changes: 40 additions & 0 deletions src/t3/ClipboardDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/****************************************************************************
* Custom dialog - Clipboard browser
* Author: Bill Forster
* License: MIT license. Full text of license is in associated file LICENSE
* Copyright 2010-2014, Bill Forster <billforsternz at gmail dot com>
****************************************************************************/
#define _CRT_SECURE_NO_DEPRECATE
#include "GameLogic.h"
#include "ClipboardDialog.h"

// ClipboardDialog constructors
ClipboardDialog::ClipboardDialog
(
wxWindow *parent,
GamesCache *gc,
GamesCache *gc_clipboard,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style
) : PgnDialog( parent, gc, gc_clipboard, id, pos, size, style )
{
}

wxSizer *ClipboardDialog::GdvAddExtraControls()
{
wxSizer *vsiz_panel_button1 = PgnDialog::GdvAddExtraControls();
filter_ctrl = new wxCheckBox( this, ID_DB_CHECKBOX,
wxT("&Clipboard as temp database"), wxDefaultPosition, wxDefaultSize, 0 );
vsiz_panel_button1->Add(filter_ctrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
filter_ctrl->SetValue( objs.gl->db_clipboard );
return vsiz_panel_button1;
}

void ClipboardDialog::OnCheckBox( bool checked )
{
objs.gl->db_clipboard = checked;
}


37 changes: 37 additions & 0 deletions src/t3/ClipboardDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/****************************************************************************
* Custom dialog - Clipboard browser
* Author: Bill Forster
* License: MIT license. Full text of license is in associated file LICENSE
* Copyright 2010-2014, Bill Forster <billforsternz at gmail dot com>
****************************************************************************/
#ifndef CLIPBOARD_DIALOG_H
#define CLIPBOARD_DIALOG_H
#include "wx/wx.h"
#include "GameDocument.h"
#include "PgnDialog.h"

// ClipboardDialog class declaration
class ClipboardDialog: public PgnDialog
{
public:

// Constructors
ClipboardDialog
(
wxWindow *parent,
GamesCache *gc,
GamesCache *gc_clipboard,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
);

// Overrides
virtual wxSizer *GdvAddExtraControls();
virtual void OnCheckBox( bool checked );

};


#endif // CLIPBOARD_DIALOG_H
76 changes: 76 additions & 0 deletions src/t3/CompactGame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/****************************************************************************
* Compact game representation
* Author: Bill Forster
* License: MIT license. Full text of license is in associated file LICENSE
* Copyright 2010-2015, Bill Forster <billforsternz at gmail dot com>
****************************************************************************/

#ifndef COMPACT_GAME_H
#define COMPACT_GAME_H
#include <string>
#include <vector>
#include <memory>
#include "thc.h"

class Roster
{
public:
std::string white;
std::string black;
std::string event;
std::string site;
std::string result;
std::string round;
std::string date;
std::string eco;
std::string white_elo;
std::string black_elo;
std::string fen;
};

class GameDocument;

class CompactGame
{
public:
CompactGame() { game_id=0; transpo_nbr=0; }
Roster r;
thc::ChessPosition start_position;
std::vector< thc::Move > moves;

// temp stuff hopefully
int game_id;
int transpo_nbr;

std::string Description();
void Upscale( GameDocument &gd ); // to GameDocument
void Downscale( GameDocument &gd ); // from GameDocument
bool HaveStartPosition() { return (r.fen.length() > 0 ); }
thc::ChessPosition &GetStartPosition() { if( r.fen.length()>0 ) start_position.Forsyth(r.fen.c_str()); return start_position; }

// Return index into vector where start position found
bool FindPositionInGame( uint64_t hash_to_match, int &idx )
{
thc::ChessRules cr = GetStartPosition();
size_t len = moves.size();
uint64_t hash = cr.Hash64Calculate();
bool found = (hash==hash_to_match);
idx = 0;
for( size_t i=0; !found && i<len; i++ )
{
thc::Move mv = moves[i];
hash = cr.Hash64Update( hash, mv );
if( hash == hash_to_match )
{
found = true;
idx = static_cast<int>(i+1);
break;
}
cr.PlayMove(mv);
}
return found;
}

};

#endif // COMPACT_GAME_H
Loading

0 comments on commit 384dd24

Please sign in to comment.