Skip to content

Commit

Permalink
Moved information to the right side of the window
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-bovet committed May 9, 2021
1 parent b1ed745 commit 1b5d8f2
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 56 deletions.
12 changes: 6 additions & 6 deletions BChess.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
A79515AA25ABE31100AEA95F /* SquareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515A825ABE31100AEA95F /* SquareView.swift */; };
A79515B425ABE34300AEA95F /* TopInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515B325ABE34300AEA95F /* TopInformationView.swift */; };
A79515B525ABE34300AEA95F /* TopInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515B325ABE34300AEA95F /* TopInformationView.swift */; };
A79515BF25ABE36700AEA95F /* BottomInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515BE25ABE36700AEA95F /* BottomInformationView.swift */; };
A79515C025ABE36700AEA95F /* BottomInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515BE25ABE36700AEA95F /* BottomInformationView.swift */; };
A79515BF25ABE36700AEA95F /* InformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515BE25ABE36700AEA95F /* InformationView.swift */; };
A79515C025ABE36700AEA95F /* InformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515BE25ABE36700AEA95F /* InformationView.swift */; };
A79515CA25ABE38F00AEA95F /* LastMoveModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515C925ABE38F00AEA95F /* LastMoveModifier.swift */; };
A79515CB25ABE38F00AEA95F /* LastMoveModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515C925ABE38F00AEA95F /* LastMoveModifier.swift */; };
A79515D525ABE3A400AEA95F /* SelectionModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = A79515D425ABE3A400AEA95F /* SelectionModifier.swift */; };
Expand Down Expand Up @@ -258,7 +258,7 @@
A795159D25ABE1D700AEA95F /* PiecesFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PiecesFactory.swift; sourceTree = "<group>"; };
A79515A825ABE31100AEA95F /* SquareView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SquareView.swift; sourceTree = "<group>"; };
A79515B325ABE34300AEA95F /* TopInformationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopInformationView.swift; sourceTree = "<group>"; };
A79515BE25ABE36700AEA95F /* BottomInformationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomInformationView.swift; sourceTree = "<group>"; };
A79515BE25ABE36700AEA95F /* InformationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InformationView.swift; sourceTree = "<group>"; };
A79515C925ABE38F00AEA95F /* LastMoveModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LastMoveModifier.swift; sourceTree = "<group>"; };
A79515D425ABE3A400AEA95F /* SelectionModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectionModifier.swift; sourceTree = "<group>"; };
A79515DF25ABE3D300AEA95F /* Selection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Selection.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -534,7 +534,7 @@
A79515D425ABE3A400AEA95F /* SelectionModifier.swift */,
A79515A825ABE31100AEA95F /* SquareView.swift */,
A79515B325ABE34300AEA95F /* TopInformationView.swift */,
A79515BE25ABE36700AEA95F /* BottomInformationView.swift */,
A79515BE25ABE36700AEA95F /* InformationView.swift */,
A795163C25ABE66600AEA95F /* BoardView.swift */,
A79515F525ABE44000AEA95F /* PiecesView.swift */,
A7A30EDC25AEBD7C00729432 /* LabelsView.swift */,
Expand Down Expand Up @@ -878,7 +878,7 @@
A7FE31EE25AA96B900A75936 /* ChessMoveGenerator.cpp in Sources */,
A79514EC25AAE2C400AEA95F /* FENgineInfo+Extension.swift in Sources */,
A79515EB25ABE41000AEA95F /* Position.swift in Sources */,
A79515BF25ABE36700AEA95F /* BottomInformationView.swift in Sources */,
A79515BF25ABE36700AEA95F /* InformationView.swift in Sources */,
A7FE31EB25AA96B900A75936 /* MoveList.cpp in Sources */,
A7FE324D25AAD61200A75936 /* FEngineMove.mm in Sources */,
A77F66D525A832270030E61D /* BChessUIApp.swift in Sources */,
Expand Down Expand Up @@ -925,7 +925,7 @@
A7FE321A25AA96D000A75936 /* ChessBoardHash.cpp in Sources */,
A79514F925AAE2C500AEA95F /* FENgineInfo+Extension.swift in Sources */,
A79515EC25ABE41000AEA95F /* Position.swift in Sources */,
A79515C025ABE36700AEA95F /* BottomInformationView.swift in Sources */,
A79515C025ABE36700AEA95F /* InformationView.swift in Sources */,
A7FE31FD25AA96C500A75936 /* ChessState.cpp in Sources */,
A7FE321925AA96D000A75936 /* FFEN.cpp in Sources */,
A7BC72E52636003F008FBBB4 /* NewGameView.swift in Sources */,
Expand Down
88 changes: 88 additions & 0 deletions BChess.xcodeproj/xcshareddata/xcschemes/BChess (macOS).xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A77F66BA25A832270030E61D"
BuildableName = "BChess.app"
BlueprintName = "BChess (macOS)"
ReferencedContainer = "container:BChess.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A77F66CD25A832270030E61D"
BuildableName = "Tests macOS.xctest"
BlueprintName = "Tests macOS"
ReferencedContainer = "container:BChess.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A77F66BA25A832270030E61D"
BuildableName = "BChess.app"
BlueprintName = "BChess (macOS)"
ReferencedContainer = "container:BChess.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A77F66BA25A832270030E61D"
BuildableName = "BChess.app"
BlueprintName = "BChess (macOS)"
ReferencedContainer = "container:BChess.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 1 addition & 1 deletion Shared/Engine/Engine/ChessEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ChessEngine {
}

std::string getPGNForDisplay() {
return FPGN::getGame(game, FPGN::Formatting::history);
return FPGN::getGame(game, FPGN::Formatting::history, 0, game.getNumberOfMoves());
}

std::string getPieceAt(File file, Rank rank) {
Expand Down
2 changes: 1 addition & 1 deletion Shared/Engine/Engine/ChessGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool ChessGame::canUndoMove() {
}

bool ChessGame::canRedoMove() {
return moveIndexes.moveCursor < getNumberOfMoves();
return moveIndexes.moveCursor < moveIndexes.moves.size();
}

void ChessGame::undoMove() {
Expand Down
17 changes: 11 additions & 6 deletions Shared/Engine/Helpers/FPGN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ static void getPGN(ChessBoard board, // The chess board representation which is
std::string & pgn, // The PGN being constructed
int moveIndex, // The current move index
int fromMoveIndex, // The move index at which we starts to build up the PGN
int toMoveIndex, // The move index at which to stop building up the PGN
int fullMoveIndex, // The number of full move that have been done so far
bool mainLine, // True if this node/move represents the main line, false if it represents a variation
bool recursive, // True if this method should continue to traverse the next move and all its variation, false to just output this move and return
Expand All @@ -762,6 +763,10 @@ static void getPGN(ChessBoard board, // The chess board representation which is
if (formatting == FPGN::Formatting::line && moveIndex == fromMoveIndex && !skip) {
pgn = "";
}

if (moveIndex >= toMoveIndex && !skip) {
return;
}

FPGN::SANType sanType = FPGN::SANType::full;
auto matchingMoves = getMatchingMoves(board, MOVE_TO(move), piece, MOVE_PROMOTION_PIECE(move), FileUndefined, RankUndefined);
Expand Down Expand Up @@ -850,31 +855,31 @@ static void getPGN(ChessBoard board, // The chess board representation which is
// If there is only one variation, it is easy: it is the main line
// so continue recursively to traverse it.
auto & main = node.variations[0];
getPGN(board, formatting, main, pgn, moveIndex+1, fromMoveIndex, fullMoveIndex, /*mainline*/true, /*recursive*/true, /*skip*/false);
getPGN(board, formatting, main, pgn, moveIndex+1, fromMoveIndex, toMoveIndex, fullMoveIndex, /*mainline*/true, /*recursive*/true, /*skip*/false);
} else {
// If there are more than one variation, we need to print first the main variation but for only one move
// For example: 1. e4 e5
auto & main = node.variations[0];
getPGN(board, formatting, main, pgn, moveIndex+1, fromMoveIndex, fullMoveIndex, /*mainline*/true, /*recursive*/false, /*skip*/false);
getPGN(board, formatting, main, pgn, moveIndex+1, fromMoveIndex, toMoveIndex, fullMoveIndex, /*mainline*/true, /*recursive*/false, /*skip*/false);

// And then print all the other variations in full (recursively)
// For example: 1. e4 e5 (1... d5)
for (int vindex=1; vindex<node.variations.size(); vindex++) {
auto & vnode = node.variations[vindex];
pgn += " (";
getPGN(board, formatting, vnode, pgn, moveIndex+1, fromMoveIndex, fullMoveIndex, /*mainline*/false, /*recursive*/true, /*skip*/false);
getPGN(board, formatting, vnode, pgn, moveIndex+1, fromMoveIndex, toMoveIndex, fullMoveIndex, /*mainline*/false, /*recursive*/true, /*skip*/false);
pgn += ")";
}

// And finally resume the main line output, recursively, but skipping this time the next move
// because it was already output above
// For example: 1. e4 e5 (1... d5) 2. Nf3 *
getPGN(board, formatting, main, pgn, moveIndex+1, fromMoveIndex, fullMoveIndex, /*mainline*/true, /*recursive*/true, /*skip*/true);
getPGN(board, formatting, main, pgn, moveIndex+1, fromMoveIndex, toMoveIndex, fullMoveIndex, /*mainline*/true, /*recursive*/true, /*skip*/true);
}
}
}

std::string FPGN::getGame(ChessGame game, Formatting formatting, int fromIndex) {
std::string FPGN::getGame(ChessGame game, Formatting formatting, int fromIndex, int toIndex) {
// Game used to compute the optimum PGN representation for each move
ChessBoard outputBoard;
FFEN::setFEN(game.initialFEN, outputBoard);
Expand All @@ -888,7 +893,7 @@ std::string FPGN::getGame(ChessGame game, Formatting formatting, int fromIndex)
if (vindex > 0) {
pgn += " (";
}
getPGN(outputBoard, formatting, node, pgn, 0, fromIndex, fullMoveIndex, /*mainline*/vindex == 0, /*recursive*/true, /*skip*/false);
getPGN(outputBoard, formatting, node, pgn, 0, fromIndex, toIndex, fullMoveIndex, /*mainline*/vindex == 0, /*recursive*/true, /*skip*/false);
if (vindex > 0) {
pgn += ")";
}
Expand Down
3 changes: 2 additions & 1 deletion Shared/Engine/Helpers/FPGN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class FPGN {
// fromIndex: the index from which to start building the PGN. Used to display a line from a game during analysis,
// which means we only want to display the game after the current move (to show the thinking of the computer).
// This parameter takes effect only if the Formatting is set to line
static std::string getGame(ChessGame game, Formatting formatting = FPGN::Formatting::storage, int fromIndex = 0);
// toIndex: the index at which to stop building the PGN.
static std::string getGame(ChessGame game, Formatting formatting = FPGN::Formatting::storage, int fromIndex = 0, int toIndex = INT_MAX);

private:
std::string pgn = "";
Expand Down
47 changes: 24 additions & 23 deletions Shared/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,33 @@ struct ContentView: View {
@State private var newGameSheetEditMode = false

var body: some View {
VStack(alignment: .leading) {
if (showInfo || document.state != .play) {
HStack {
TopInformationView(document: document)
Spacer()
AnalyzeActionsView(document: $document)
.hide(document.state == .play)
Spacer()
HStack(alignment: .top) {
VStack(alignment: .leading) {
ColorInformationView(document: $document, isWhite: document.rotated ? true: false)
ZStack {
BoardView(document: $document)
.if(document.state == .analyze) {
$0.border(Color.yellow, width: 4)
}
.if(document.state == .train) {
$0.border(Color.green, width: 4)
}
LabelsView(document: $document)
PiecesView(document: $document)
}
.padding()
.padding(.bottom, 20) // Because the labels are "leaking" a bit below the board space itself
ColorInformationView(document: $document, isWhite: document.rotated ? false: true)
}

ZStack {
BoardView(document: $document)
.if(document.state == .analyze) {
$0.border(Color.yellow, width: 4)
}
.if(document.state == .train) {
$0.border(Color.green, width: 4)
}
LabelsView(document: $document)
PiecesView(document: $document)
}.padding()

if (showInfo) {
BottomInformationView(document: document)
.padding(.top)
VStack {
AnalyzeActionsView(document: $document)
.hide(document.state == .play)

if (showInfo) {
InformationView(document: document)
.frame(minWidth: 250, idealWidth: 250, maxWidth: 300, alignment: .center)
}
}
}
.padding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import SwiftUI

struct BottomInformationView: View {
struct InformationView: View {

let document: ChessDocument

Expand Down Expand Up @@ -64,29 +64,29 @@ struct BottomInformationView: View {
VStack(alignment: .leading) {
if let opening = document.engine.openingName() {
Text(opening)
.padding(.bottom)
} else {
if document.state == .play {
HStack {
Text("Eval").bold()
HStack() {
Image(systemName: "cpu")
Text(value())
}
.padding(.bottom)
HStack {
Text("Stats").bold()
Text(Image(systemName: "speedometer"))
Text(speed())
}
.padding(.bottom)
}
}
HStack {
Text("Moves").bold()
Text(document.engine.pgnFormattedForDisplay())
}
Text(document.engine.pgnFormattedForDisplay())
}
}
}

struct BottomInformationView_Previews: PreviewProvider {
static var previews: some View {
let doc = ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 *")
BottomInformationView(document: doc)
InformationView(document: doc)
}
}
17 changes: 8 additions & 9 deletions Shared/Views/TopInformationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

struct ColorInformationView: View {

let document: ChessDocument
@Binding var document: ChessDocument
let isWhite: Bool

func capturedPieces() -> [String] {
Expand Down Expand Up @@ -86,13 +86,12 @@ struct ColorInformationView: View {

struct TopInformationView: View {

let document: ChessDocument


@Binding var document: ChessDocument

var body: some View {
VStack(alignment: .leading) {
ColorInformationView(document: document, isWhite: true)
ColorInformationView(document: document, isWhite: false)
ColorInformationView(document: $document, isWhite: true)
ColorInformationView(document: $document, isWhite: false)
}
}
}
Expand All @@ -101,15 +100,15 @@ struct TopInformationView_Previews: PreviewProvider {
static var previews: some View {
Group {
let doc = ChessDocument(pgn: "1. e4 e5")
TopInformationView(document: doc)
TopInformationView(document: .constant(doc))
}
Group {
let doc = ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 ")
TopInformationView(document: doc)
TopInformationView(document: .constant(doc))
}
Group {
let doc = ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 5. d4 exd4 6. Qxd4 Qxd4 7. Nd5 Nxd5 8. Bb5+ c6 9. Bxc6+ Nxc6 *")
TopInformationView(document: doc)
TopInformationView(document: .constant(doc))
}
}
}

0 comments on commit 1b5d8f2

Please sign in to comment.