bpaul-chess

UCI chess engine to replace Omelette Chess Engine
Log | Files | Refs | README | LICENSE

commit 6538c57c130b7b9406b9b8a87950132b6af2a645
parent cb627e5c71f581ddc91e2da1760edd6e5efd80f9
Author: benjamin paul <bpaul@bpaul.xyz>
Date:   Sun,  8 Aug 2021 00:12:46 +1000

Some rearrangements plus a failed attempt at optimization

Diffstat:
A.clang-format | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MMakefile | 5++++-
Msrc/main.c | 16+++++++---------
3 files changed, 109 insertions(+), 10 deletions(-)

diff --git a/.clang-format b/.clang-format @@ -0,0 +1,98 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveBitFields: Consecutive +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: Consecutive +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: AllDefinitions +AlwaysBreakBeforeMultilineStrings: false +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakStringLiterals: true +ColumnLimit: 79 +ContinuationIndentWidth: 4 +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +# idk what this is but +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseBlocks: false +IndentCaseLabels: false +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +# i will figure this stuff out as i go +PenaltyBreakAssignment: 0 +PenaltyBreakBeforeFirstCallParameter: 0 +PenaltyBreakComment: 0 +PenaltyBreakFirstLessLess: 0 +PenaltyBreakString: 0 +PenaltyBreakTemplateDeclaration: 0 +PenaltyExcessCharacter: 0 +PenaltyReturnTypeOnItsOwnLine: 0 +PenaltyIndentedWhitespace: 0 +# gnu's settings +#PenaltyBreakAssignment: 2 +#PenaltyBreakBeforeFirstCallParameter: 19 +#PenaltyBreakComment: 300 +#PenaltyBreakFirstLessLess: 120 +#PenaltyBreakString: 1000 +#PenaltyBreakTemplateDeclaration: 10 +#PenaltyExcessCharacter: 1000000 +#PenaltyReturnTypeOnItsOwnLine: 60 +#PenaltyIndentedWhitespace: 0 + +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false + +TabWidth: 4 +UseCRLF: false +UseTab: AlignWithSpaces +... + diff --git a/Makefile b/Makefile @@ -3,7 +3,7 @@ NAME = bpaul-chess CC = cc -CFLAGS = -O2 +CFLAGS = -O3 -flto OBJS = src/main.o @@ -11,3 +11,6 @@ all: $(NAME) $(NAME): $(OBJS) $(CC) $(LDFLAGS) -o $(NAME) $(OBJS) + +clean: + rm $(NAME) $(OBJS) diff --git a/src/main.c b/src/main.c @@ -1,13 +1,11 @@ -#include <string.h> #include <stdbool.h> #include <stdio.h> +#include <string.h> #define VERSION "v0.0.1" -bool -cmd(const char *buf, const char *command) { - return strncmp(buf, command, strlen(command)) == 0; -} +/* sizeof magically gets the length of the string! (plus \0) */ +#define CMD(s) strncmp(buf, s, sizeof(s)-1) == 0 int main() { @@ -27,13 +25,13 @@ main() { for (;;) { fgets(buf, 2048, stdin); - if (cmd(buf, "uci")) { - printf("id name bpaul-chess %s\n", VERSION); + if (CMD("uci")) { + puts("id name bpaul-chess " VERSION); puts("id author Benjamin Paul"); puts("uciok"); - } else if (cmd(buf, "isready")) { + } else if (CMD("isready")) { puts("readyok"); - } else if (cmd(buf, "quit")) { + } else if (CMD("quit")) { break; } }