Commit f2e2fcd0 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Start anew

parent b4c2f038
;; .dir-locals.el.in
;;
;; Copyright (C) 2017, 2018 Vivien Kraus <vivien@planete-kraus.eu>
;;
;; This program is free software: you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see
;; <http://www.gnu.org/licenses/>.
((nil
(compile-command . "cd @abs_top_builddir@ && make -j 4")
(eval
. (setq company-clang-arguments
(split-string
"
-I@abs_top_srcdir@
-I@abs_top_builddir@
@CFLAGS@
@libunistring_CFLAGS@
@CODE_COVERAGE_CFLAGS@
@CPPFLAGS@
@asan_CFLAGS@
-I@abs_top_srcdir@/src
-I@abs_top_builddir@/src
-I@abs_top_srcdir@/src/core
-I@abs_top_builddir@/src/core
-I@abs_top_srcdir@/src/cards
-I@abs_top_builddir@/src/cards
-I@abs_top_srcdir@/src/command
-I@abs_top_builddir@/src/command
-I@abs_top_srcdir@/src/lexer
-I@abs_top_builddir@/src/lexer
-I@abs_top_srcdir@/src/parser
-I@abs_top_builddir@/src/parser
-I@abs_top_srcdir@/src/application
-I@abs_top_builddir@/src/application
-I@abs_top_srcdir@/src/program
-I@abs_top_builddir@/src/program
"))))
Vivien Kraus
Table of Contents
_________________
Vivien Kraus <vivien@planete-kraus.eu>
FROM debian:stable
RUN apt-get update
RUN apt-get install -y --no-install-recommends texlive-base texlive-latex-base git ca-certificates texlive-fonts-recommended texlive-generic-recommended autoconf automake gettext autopoint libtool texinfo gnulib autoconf-archive gobject-introspection make gcc valac valac-vapi gtk-doc-tools flex bison gperf nettle-dev libgtk-3-dev libgirepository1.0-dev emacs org-mode indent doxygen graphviz lcov dejagnu check libxml2-utils xsltproc wget gengetopt help2man libreadline-dev libunistring-dev valgrind autogen
RUN apt-get upgrade -y
MAINTAINER framagit.org/gugurumbe/tarot
\ No newline at end of file
......@@ -16,10 +16,7 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
SUBDIRS = po lib-library lib-program
if NEED_LIBOPTS
SUBDIRS += $(LIBOPTS_DIR)
endif # NEED_LIBOPTS
SUBDIRS = po lib-library
AUTOMAKE_OPTIONS = subdir-objects
bin_PROGRAMS =
......@@ -49,13 +46,15 @@ dist_noinst_SCRIPTS = \
build-aux/git-version-gen
nodist_noinst_DATA =
ACLOCAL_AMFLAGS = -I m4 -I lib-library/m4 -I lib-program/m4
ACLOCAL_AMFLAGS = -I m4 -I lib-library/m4
EXTRA_DIST = \
tarot.org \
setup.el \
AUTHORS.org \
m4/gnulib-cache.m4 \
$(top_srcdir)/.version
lib-library/m4/gnulib-cache.m4 \
$(top_srcdir)/.version \
.gitlab-ci.yml \
.gitignore
BUILT_SOURCES = \
$(top_srcdir)/.version
CLEANFILES =
......@@ -83,6 +82,7 @@ TEST_EXTENSIONS = .tarot
TAROT_LOG_COMPILER = $(SHELL) $(top_srcdir)/run-tarot.sh
AM_TAROT_LOG_FLAGS =
include ci/Makefile.am
include doc/Makefile.am
include src/Makefile.am
include games/Makefile.am
......
Waiting for the release...
\ No newline at end of file
________________________________________
LIBTAROT
Vivien Kraus <vivien@planete-kraus.eu>
________________________________________
Table of Contents
_________________
Welcome to the libtarot source code! This is a pure library. For now
it does not, but it could bind to other C libraries, provided that these
libraries would not manage resources like memory, the file system, and
not mess with the control flow, like abort (except for assertions) or
setjump / longjump.
You will find the usual autogen.sh, configure.ac, Makefile.am, a
pkg-config configuration file, a script in build-aux to guess the
development version number, the manual under doc/, and the gnulib module
(assert) under lib/.
......@@ -25,18 +25,5 @@ gnulib-tool --libtool \
--m4-base=lib-library/m4 \
--macro-prefix=gl_lib \
--import assert || exit 1
gnulib-tool --libtool \
--lib=libgnuprogram \
--source-base=lib-program \
--m4-base=lib-program/m4 \
--macro-prefix=gl_prog \
--import malloc-gnu getopt-gnu gettext-h setlocale xalloc \
stdnoreturn readline libunistring \
|| exit 1
rm -rf libopts || exit 1
(gunzip -c `autoopts-config libsrc` | tar -xvf -) || exit 1
mv libopts-*.*.* libopts || exit 1
cp -fp libopts/m4/*.m4 m4/ || exit 1
cp -fp snippet/_Noreturn.h libopts/ || exit 1
autoreconf -vif || exit 1
rm doc/tarot.texi || exit 1
# Makefile.am
#
# Copyright (C) 2018 Vivien Kraus <vivien@planete-kraus.eu>
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
EXTRA_DIST += %reldir%/dist.sh %reldir%/pages.sh
......@@ -23,7 +23,9 @@ sh autogen.sh || exit 1
|| (cat config.log ; exit 1) \
|| exit 1
make indent || exit 1
(cd lib && make -j 16) || exit 1
(cd lib-library && make -j 16) || exit 1
## Non parallel
make dist || exit 1
make -j 16 distcheck || exit 1
make -j 16 check || exit 1
make -j 16 install install-html || exit 1
......@@ -33,7 +35,7 @@ cd ../../ || exit 1
tar xf tarot-*.tar.gz || exit 1
cd tarot-* || exit 1
DIST_TOP=$(pwd)
cd $CLEAN_TOP/program || exit 1
cd $CLEAN_TOP || exit 1
OK="yes"
for source in $(find . -type f)
do
......@@ -42,9 +44,12 @@ do
echo "Ignoring PO file $source, as it has a date in it.";;
*.md)
echo "Ignoring Markdown file $source, as it may be non-reproducibly generated by org-mode.";;
*/.git/*);;
*)
if ! $(diff $source $DIST_TOP/$source)
if diff $source $DIST_TOP/$source
then
echo "$source: OK"
else
echo "ERROR: $source has been modified since check-in, or ignored from the distribution. Is it automatically generated? Did you forget to indent it? Did you forget to include it as distributed in Automake?"
OK="no"
fi;;
......@@ -59,6 +64,6 @@ fi
## Nice!
cd $SOURCE_TOP || exit 1
mkdir -p $SOURCE_TOP/public || exit 1
cp $SOURCE_TOP/program/.version \
cp $SOURCE_TOP/.version \
$SOURCE_TOP/public/version || exit 1
cp ../tarot-*.tar.gz $SOURCE_TOP/public/ || exit 1
cp tarot-*.tar.gz $SOURCE_TOP/public/ || exit 1
......@@ -6,11 +6,10 @@ apt-get update
apt-get upgrade -y
apt-get install -y --no-install-recommends \
build-essential \
libreadline-dev \
libunistring-dev \
texinfo \
pkg-config \
libuile-2.0-dev guile-2.0
guile-2.0 \
guile-2.0-dev
cp public/tarot-$VERSION.tar.gz . || exit 1
tar xf tarot-$VERSION.tar.gz || exit 1
mkdir build || exit 1
......
......@@ -6,13 +6,12 @@ AC_INIT([tarot],
m4_esyscmd([build-aux/git-version-gen .tarball-version]),
[vivien@planete-kraus.eu])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIRS([m4 lib-library/m4 lib-program/m4])
AC_CONFIG_MACRO_DIRS([m4 lib-library/m4])
# Checks for programs.
AC_PROG_CC
AC_PROG_CC_STDC
gl_lib_EARLY
gl_prog_EARLY
AM_INIT_AUTOMAKE
AM_PROG_AR
LT_INIT
......@@ -41,7 +40,6 @@ AC_PROG_YACC
# Checks for libraries.
gl_lib_INIT
gl_prog_INIT
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.19])
LIBOPTS_CHECK
......@@ -69,7 +67,6 @@ AC_CONFIG_FILES([
Makefile
po/Makefile.in
lib-library/Makefile
lib-program/Makefile
src/libtarot.pc
])
......
......@@ -26,10 +26,12 @@ EXTRA_DIST += \
%reldir%/style.css \
%reldir%/ChangeLog \
%reldir%/tarot.org \
%reldir%/setup.el \
%reldir%/invoke-tarot.texi
%reldir%/setup.el
%reldir%/tarot.texi: %reldir%/tarot.org %reldir%/setup.el %reldir%/invoke-tarot.texi .version
%reldir%/tarot.texi $(SCM_TESTS): \
%reldir%/tarot.org \
%reldir%/setup.el \
.version
$(AM_V_GEN) (cd $(srcdir)/%reldir% && \
LIBTAROT_VERSION="$(VERSION)" \
$(EMACS) --batch -q \
......
(defun package-version () (getenv "LIBTAROT_VERSION"))
(setq org-confirm-babel-evaluate nil)
(setq geiser-default-implementation 'guile)
(require 'ox-texinfo)
......@@ -587,83 +587,139 @@ the previously computed amount. Then the defendant have added
A new game can then begin, with the new first player being the
previous second.
* The tarot program
#+PINDEX: tarot-assistant
#+CINDEX: Invoking @command{tarot-assistant}
The {{{command(tarot-assistant)}}} program accepts a number arguments.
It also has several environment variables that orverride the default
behavior.
** tarot-assistant Invocation
#+texinfo: @include invoke-tarot.texi
** Command-line interface
The command-line interface will be similar in functionnality to the
batch arguments parsing. So, we have a {{{command(help)}}} command to
print some help about the different commands, and
{{{command(version)}}}. You can also find a {{{command(license)}}} to
assert the license of the package. The other commands are discussed
below.
*** The {{{command(new)}}} command
This command restarts the current game. It does not have arguments.
*** TODO The {{{command(status)}}} command
*** The game event commands
These commands are {{{command(setup)}}}, {{{command(deal)}}},
{{{command(bid)}}}, {{{command(decl)}}}, {{{command(call)}}},
{{{command(dog)}}}, {{{command(discard)}}}, {{{command(dog)}}},
{{{command(discard)}}}, {{{command(handful)}}}, and
{{{command(play)}}}. All of them may be preceded by
{{{command(check)}}}, to only check the action, and not actually
perform it.
**** The {{{command(setup)}}} command
It is invoked as:
- ~setup 5 with call~ for a 5-player game with call;
- ~setup 4~ for a standard 4-player variant;
- ~setup 3~ for 3 players.
**** The {{{command(deal)}}} command
It has two modes of execution: deal for all players at once, or deal
for a specific player. If you want to deal to all players, you must
pass 78 player arguments, one for each card.
So for instance, if your command starts with {{{command(deal P3 P2 P1
P4 ...)}}}, then the ace of hearts (the first card) would be given to
the third player, the two of hearts to the second player, the three of
hearts to the first player, the four of hearts to the fourth player,
and so on.
The card order is:
- the /hearts/;
- the /clubs/;
- the /diamonds/;
- the /spades/;
- the /trumps/;
- the /excuse/.
You can invoke this command with two different modes:
- ~deal [CARDS]... to PN~ to deal all cards to player number N;
- ~deal PN1 PN2 ...~ to deal the ace of hearts to player number N1,
the two of hearts to N2, and so on for the other 76 cards. You can
use a player number strictly greater than the total number of
players to indicate a card in the dog.
**** The {{{command(bid)}}} command
It only takes one argument, the bid, as =pass=, =take=, =push=,
=straight-keep= or =double-keep=.
**** The {{{command(decl)}}} command
It takes one argument, either =pass= (not to declare slam) or =slam=
(to declare slam).
**** The {{{command(call)}}} and {{{command(play)}}} command
These commands accept one argument, the face card that the taker wants
to call, or the card that the next player wants to play.
**** The {{{command(dog)}}}, {{{command(discard)}}} and {{{command(handful)}}} command
It accepts the cards of the dog / discard / handful. The discard may
be empty, meaning we don't know it, or partial, if the taker discards
some trumps.
* Bringing tarot to your program
This section serves as libtarot API documentation, tutorial for
integration in your favorite platform, and implementation of the
reference program. All code in this section is dual licensed under
the GNU GPL version 3 or later.
** Introduction
The libtarot library is a repository of pure portable code, however it
does not manage memory nor any other resources. For this task, you
may want to use your favorite less portable platform. In our case, we
will use the GNU Guile platform which is the recommended way for the
GNU project. We will leverage its foreign function interface, to use
native code without having to compile binding layers.
** Generating a game
For this first program, we will generate a game from a random seed.
We need the following options:
- the number of players, =n-players=, between 3 and 5;
- whether a call is allowed;
- the model file for the AI, which is an INI file where each game
feature is associated to a weight or a list of weight;
- the random seed, which is a possibly large number. However we will
treat as a byte vector instead of a big int.
To manage these options and the configuration file format, we could
have used =guile-config=, but it is not established enough to be worth
a dependency. So we will do some things by hand.
So without further ado, let's run Guile.
#+BEGIN_SRC scheme
"Hello, guile!"
#+END_SRC
In fact, we want a command line argument parser. For this we use the
=ice-9/getopt-long= guile module. As we are object-oriented, we use
guile's framework, =GOOPS=. This means we have to define a class for
the base application (code [[scm-define-tarot-application-class]]), and a
class for the generator application (code
[[scm-define-tarot-application-generate-class]]).
#+name: scm-define-tarot-application-class
#+caption: Class definition: =<tarot-application>=
#+BEGIN_SRC scheme :eval no
(define-class <tarot-application> ())
#+END_SRC
#+name: scm-define-tarot-application-generate-class
#+caption: Class definition: =<tarot-application-generate>=
#+BEGIN_SRC scheme :eval no
(define-class <tarot-application-generate> (<tarot-application>)
n-players with-call? model-file seed)
#+END_SRC
We now want to actually parse the command-line arguments and return a
=<tarot-application-generate>=. We first define the predicate to
check whether the argument value is acceptable, then we define the
options with their name, abbreviation, and value domain, and finally
we construct the new application. However, we must also implement the
=--help= and =--version= arguments. While the former is easy to
implement (provided we have gettext available), the latter needs the
package version (code [[el-package-version]]).
#+name: el-package-version
#+caption: Version number for the package
#+BEGIN_SRC emacs-lisp
(package-version)
#+END_SRC
#+name: scm-define-tarot-application-generate-init
#+BEGIN_SRC scheme :eval no :noweb yes
(define (tarot-application-generate-init args)
(let* ((check-is-number (lambda (str) (and (string->number str) #t)))
(option-spec '((version (single-char #\V) (value #f))
(help (single-char #\h) (value #f))
(n-players (single-char #\n) (value #t)
(predicate check-is-number))
(with-call (single-char #\c) (value #f))
(model (single-char #\m) (value #t))
(seed (single-char #\s) (value #t))))
(options (getopt-long args option-spec))
(help-wanted (option-ref options 'help #f))
(version-wanted (option-ref options 'version #f))
(work (not (or help-wanted version-wanted)))
(n-players (and work (string->number (option-ref options 'n-players "4"))))
(with-call (and work (option-ref options 'with-call #f)))
(model (and work (open-file (option-ref options 'model #f) "rb")))
(seed (and work (string->bytevector (option-ref options 'seed "") "UTF-8"))))
(if (or help-wanted version-wanted)
(begin
(if version-wanted
(display (_ "tarot version <<el-package-version()>>")))
(if help-wanted
(format #t (_ "\
tarot-generate [OPTIONS]
-h, --help Print this help and exit
-V, --version Print the package version number (~a) and exit
-n, --n-players Set the number of players (between 3 and 5)
-c, --with-call Request a call in the game
-m, --model Set the AI model filename
-s, --seed Set the random seed (any string)
") "<<el-package-version()>>"))
(exit 0))
(make <tarot-application-generate>
#:n-players n-players
#:with-call? with-call
#:model-file model
#:seed seed))))
#+END_SRC
*** Requesting the help message
We only pass =--help= to check what the program tells.
#+BEGIN_SRC scheme :noweb yes :tangle ../src/scm/tarot/check/example-generate.scm :mkdirp t :shebang "#!/usr/bin/env guile" :eval no
-s
!#
(define-module (tarot check example-generate)
#:use-module (ice-9 getopt-long)
#:use-module (ice-9 i18n)
#:use-module (ice-9 iconv)
#:use-module (ice-9 format)
#:use-module (oop goops))
<<scm-define-tarot-application-class>>
<<scm-define-tarot-application-generate-class>>
(define _ gettext)
<<scm-define-tarot-application-generate-init>>
(define options (tarot-application-generate-init '("tarot-generate" "--help")))
(display "This is not displayed because the --help argument forced quit.")
(exit 1)
#+END_SRC
* GNU Free Documentation License
:PROPERTIES:
:APPENDIX: t
......
# Makefile.am
#
# Copyright (C) 2018 Vivien Kraus <vivien@planete-kraus.eu>
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
pass_tests = \
%reldir%/artificial_combo_all.tarot \
%reldir%/artificial_combo_penultimate.tarot \
%reldir%/artificial_combo.tarot \
%reldir%/artificial_combo_without_pab.tarot
TESTS += $(pass_tests)
EXTRA_DIST += \
%reldir%/artificial_combo_all.tarot.expected \
%reldir%/artificial_combo_penultimate.tarot.expected \
%reldir%/artificial_combo.tarot.expected \
%reldir%/artificial_combo_without_pab.tarot.expected \
$(pass_tests)
......@@ -51,3 +51,5 @@ USE_MSGCTXT = no
# --previous to keep previous msgids of translated messages,
# --quiet to reduce the verbosity.
MSGMERGE_OPTIONS =
install-html:
# List of source files which contain translatable strings.
src/program/options.c
src/program/main.c
src/program/lexer.c
src/program/parser.c
src/scm/tarot.scm
\ No newline at end of file
src/features/features.c
\ No newline at end of file
This diff is collapsed.
#!/bin/sh
>&2 pwd
EXPECTED="$(cat $1.expected | grep -v '^> ')"
ACTUAL="$(src/program/tarot --interactive --no-load-opts < $1 2>&1 | grep -v '^> ')"
if test "x$ACTUAL" != "x$EXPECTED"
then
>&2 echo "Failure: '$ACTUAL' != '$EXPECTED'"
exit 1
fi
FEATURES="$(src/program/tarot --export-features --no-load-opts < $1 2>&1)"
STATUS="$?"
if test "x$STATUS" != "x0" && test x$(echo "$FEATURES" | grep -v "this is not valid.") != x
then
>&2 echo "Failure: could not process the features."
exit 1
fi
rm -f features.csv
exit 0
......@@ -53,5 +53,4 @@ include %reldir%/features/Makefile.am
include %reldir%/model/Makefile.am
include %reldir%/ai/Makefile.am
include %reldir%/generator/Makefile.am
include %reldir%/program/Makefile.am
include %reldir%/scm/Makefile.am
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment