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

Merge branch '178-purge-the-useless-code' into 'develop'

Resolve "Purge the useless code"

Closes #178

See merge request !184
parents 83bd66de 2d31cf61
Pipeline #206694 passed with stages
in 43 minutes and 6 seconds
......@@ -50,14 +50,11 @@
/doc/petit-sec.c
/doc/players-and-cards
/doc/players-and-cards.c
/doc/tarot-cnn-features.man
/doc/tarot-cnn.man
/doc/tarot-deal.man
/doc/tarot-features.man
/doc/tarot-figures
/doc/tarot-mcts.man
/doc/tarot-perceptron-bootstrap.man
/doc/tarot-stacking.man
/doc/tarot-status.man
/doc/tarot-tune
/doc/tarot.info
......@@ -84,9 +81,6 @@
/ltmain.sh
/m4
/missing
/model/linear-*.h
/model/stacking.h
/model/tree-*.h
/nsi/setup.nsi
/nsi/tarot.ico
/po/*.gmo
......@@ -112,8 +106,6 @@
/snippet
/src/gettext.h
/src/libtarot/cards/check-cards
/src/libtarot/features/features-header-encoded.txt
/src/libtarot/features/features-header.txt
/src/libtarot/gobject/tarot-enums-stamp
/src/libtarot/gobject/tarot-gobject.c
/src/libtarot/gobject/tarot-gobject.h
......@@ -150,14 +142,11 @@
/src/tarot-app/resources.c
/src/tarot-app/server.c
/src/tarot-app/tarot
/src/tarot-app/tarot-cnn
/src/tarot-app/tarot-cnn-features
/src/tarot-app/tarot-deal
/src/tarot-app/tarot-en
/src/tarot-app/tarot-features
/src/tarot-app/tarot-mcts
/src/tarot-app/tarot-parser-stamp
/src/tarot-app/tarot-stacking
/src/tarot-app/tarot-status
/src/tarot-app/tarot-vala-stamp
/src/tarot-app/tarot_app.h
......
# tarot implements the rules of the tarot game
# Copyright (C) 2017, 2018, 2019 Vivien Kraus
# Copyright (C) 2017, 2018, 2019, 2020 Vivien Kraus
# 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
......@@ -49,10 +49,6 @@ deb:
- public
expire_in: 1 week
generate:
stage: check
script: "./ci/generate.sh"
pages:
stage: manual
script: "./ci/pages.sh"
......
......@@ -43,7 +43,6 @@ include screenshots/Makefile.am
include nsi/Makefile.am
include debian/Makefile.am
include flatpak/Makefile.am
include model/Makefile.am
include git-check.am
include copyright/Makefile.am
include guix/Makefile.am
......@@ -58,9 +57,9 @@ AM_CPPFLAGS += \
-DLIBTAROT_VERSION_INFO="\"$(LIBTOOL_CURRENT):$(LIBTOOL_REVISION):$(LIBTOOL_AGE)\""
AM_YFLAGS = -d
AM_CFLAGS += \
$(NETTLE_CFLAGS) $(XML_CFLAGS) $(OPENMP_CFLAGS)
$(NETTLE_CFLAGS) $(OPENMP_CFLAGS)
AM_LDADD += \
$(NETTLE_LIBS) $(XML_LIBS) $(GUILE_LIBS) $(OPENMP_LIBS) \
$(NETTLE_LIBS) $(GUILE_LIBS) $(OPENMP_LIBS) \
$(LIBTHREAD) \
$(LIB_SETLOCALE) \
$(LIB_SETLOCALE_NULL) \
......
# tarot implements the rules of the tarot game
# Copyright (C) 2018, 2019 Vivien Kraus
# Copyright (C) 2018, 2019, 2020 Vivien Kraus
# 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
......@@ -18,6 +18,4 @@ EXTRA_DIST += \
%reldir%/pages.sh \
%reldir%/check.sh \
%reldir%/mingw.sh \
%reldir%/generate.sh \
%reldir%/generate-seed.sh \
%reldir%/deb.sh
#!/bin/sh
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# Copyright (C) 2019, 2020 Vivien Kraus
# 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
......@@ -20,8 +20,6 @@ apt-get install -y \
build-essential \
guile-2.2-dev \
libglib2.0-dev \
libxml2 \
libxml2-dev \
nettle-dev \
pkg-config \
valgrind
......
#!/bin/sh
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# Copyright (C) 2019, 2020 Vivien Kraus
# 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
......@@ -22,8 +22,6 @@ apt-get install -y \
libglib2.0-dev \
libgtk-3-0 \
libgtk-3-dev \
libxml2 \
libxml2-dev \
nettle-dev \
pkg-config \
valgrind \
......
#!/bin/sh
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# Copyright (C) 2019, 2020 Vivien Kraus
# 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
......@@ -47,8 +47,6 @@ apt-get install -y \
libglib2.0-dev \
libgtk-3-dev \
libtool \
libxml2 \
libxml2-dev \
libxml2-utils \
make \
nettle-dev \
......
#!/bin/sh
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# 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, version 3 of the License.
#
# 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/>.
seed="$1"
version=$(cat ../dist/version)
for n_players in 3 4 5
do
>&2 echo "Generating $seed for version $version, $n_players players"
(tarot-deal -n $n_players -s $seed | tarot-mcts --generate -s $seed > $seed-${n_players}p.tarot-t \
&& mv $seed-${n_players}p.tarot-t dataset/generated/mcts/$seed-${n_players}p.tarot \
&& echo "no" > /tmp/all-mcts-${n_players}p-failed) \
|| >&2 echo "It failed."
(tarot-deal -n $n_players -s $seed | tarot-stacking --generate > $seed-${n_players}p.tarot-t \
&& mv $seed-${n_players}p.tarot-t dataset/generated/stacking/$version-$seed-${n_players}p.tarot \
&& echo "no" > /tmp/all-stacking-${n_players}p-failed) \
|| >&2 echo "It failed."
if [ "x$n_players" = "x5" ]
then
>&2 echo "Generating $seed for verision $version, 5 players with call"
(tarot-deal -n 5 -c -s $seed | tarot-mcts --generate -s $seed > $seed-5pc.tarot-t \
&& mv $seed-5pc.tarot-t dataset/generated/mcts/$seed-5pc.tarot \
&& echo "no" > /tmp/all-mcts-5pc-failed) \
|| >&2 echo "It failed."
(tarot-deal -n 5 -c -s $seed | tarot-stacking --generate > $seed-5pc.tarot-t \
&& mv $seed-5pc.tarot-t dataset/generated/stacking/$version-$seed-5pc.tarot \
&& echo "no" > /tmp/all-stacking-5pc-failed) \
|| >&2 echo "It failed."
fi
done
#!/bin/sh
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# 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, version 3 of the License.
#
# 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/>.
apt-get update
apt-get upgrade -y
apt-get install -y \
build-essential \
curl \
git \
guile-2.2-dev \
libcairo2-dev \
libgirepository1.0-dev \
libglib2.0-dev \
libgtk-3-dev \
libxml2 \
libxml2-dev \
nettle-dev \
parallel \
pkg-config \
valgrind
VERSION=$(cat dist/version)
cp dist/tarot-$VERSION.tar.gz . || exit 1
tar xf tarot-$VERSION.tar.gz || exit 1
mkdir build || exit 1
cd build/
../tarot-$VERSION/configure \
--enable-silent-rules=yes \
--enable-valgrind=yes \
|| (cat config.log; exit 1)
make -j 16 || exit 1
make install || exit 1
export PATH="/usr/local/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
mkdir /root/.ssh || exit 1
echo "$SSH_KEY" > /root/.ssh/id_rsa || exit 1
echo "$SSH_KEY_PUB" > /root/.ssh/id_rsa.pub || exit 1
echo "$SSH_KNOWN_HOSTS" > /root/.ssh/known_hosts || exit 1
chmod go-rwx /root/.ssh/id_rsa || exit 1
git config --global user.email "vivien@planete-kraus.eu" || exit 1
git config --global user.name "Gitlab CI for the tarot package" || exit 1
git clone git@framagit.org:play-tarot/datasets.git dataset/ || exit 1
rm -rf dataset/generated/mcts
mkdir -p dataset/generated/mcts || exit 1
mkdir -p dataset/generated/stacking || exit 1
seq 1 10 | parallel ../tarot-$VERSION/ci/generate-seed.sh {}
for check in /tmp/all-*-*-failed
do
if test "x$(cat $check)" != "xno"
then
echo "Could not generate anything for test '$check'."
exit 1
fi
done
#!/bin/sh
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# Copyright (C) 2019, 2020 Vivien Kraus
# 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
......@@ -26,7 +26,6 @@ dnf install -y \
\
mingw64-gcc \
mingw64-nettle \
mingw64-libxml2 \
mingw64-glib2 \
mingw64-cairo \
mingw64-gtk3 \
......
#!/bin/sh
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# Copyright (C) 2019, 2020 Vivien Kraus
# 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
......@@ -20,8 +20,6 @@ apt-get install -y \
build-essential \
jq \
libglib2.0-dev \
libxml2 \
libxml2-dev \
nettle-dev \
pkg-config \
texinfo \
......
......@@ -124,7 +124,6 @@ AS_IF([test "x$enable_program" != "xno"], [
])
])
AX_LIB_NETTLE([yes])
PKG_CHECK_MODULES([XML], [libxml-2.0])
AC_ARG_WITH([gobject], AS_HELP_STRING([--without-gobject], [Do not build the GObject bindings]))
WITH_GOBJECT="no"
AS_IF([test "x$with_gobject" != "xno"], [
......
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# Copyright (C) 2019, 2020 Vivien Kraus
# 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
......@@ -17,7 +17,6 @@ check_PROGRAMS += \
%reldir%/basic-initialization \
%reldir%/players-and-cards \
%reldir%/events \
%reldir%/xml \
%reldir%/petit-sec \
%reldir%/duplicate-a-posteriori \
%reldir%/dumb-ai
......@@ -25,7 +24,6 @@ check_PROGRAMS += \
%canon_reldir%_basic_initialization_LDADD = src/libtarot/libtarot.la $(AM_LDADD)
%canon_reldir%_players_and_cards_LDADD = src/libtarot/libtarot.la $(AM_LDADD)
%canon_reldir%_events_LDADD = src/libtarot/libtarot.la $(AM_LDADD)
%canon_reldir%_xml_LDADD = src/libtarot/libtarot.la $(AM_LDADD)
%canon_reldir%_petit_sec_LDADD = src/libtarot/libtarot.la $(AM_LDADD)
%canon_reldir%_duplicate_a_posteriori_LDADD = src/libtarot/libtarot.la $(AM_LDADD)
%canon_reldir%_dumb_ai_LDADD = src/libtarot/libtarot.la $(AM_LDADD)
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# Copyright (C) 2019, 2020 Vivien Kraus
# 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
......@@ -15,23 +15,9 @@
dist_man6_MANS += \
%reldir%/tarot.man \
%reldir%/tarot-status.man \
%reldir%/tarot-deal.man \
%reldir%/tarot-mcts.man \
%reldir%/tarot-stacking.man \
%reldir%/tarot-features.man \
%reldir%/tarot-cnn-features.man \
%reldir%/tarot-cnn.man \
%reldir%/tarot-perceptron-bootstrap.man
MAINTAINERCLEANFILES += \
$(srcdir)/%reldir%/tarot.man \
$(srcdir)/%reldir%/tarot-status.man \
$(srcdir)/%reldir%/tarot-deal.man \
$(srcdir)/%reldir%/tarot-mcts.man \
$(srcdir)/%reldir%/tarot-stacking.man \
$(srcdir)/%reldir%/tarot-features.man \
$(srcdir)/%reldir%/tarot-cnn-features.man \
$(srcdir)/%reldir%/tarot-cnn.man \
$(srcdir)/%reldir%/tarot-perceptron-bootstrap.man
help2man_verbose = $(help2man_verbose_@AM_V@)
......@@ -42,34 +28,6 @@ $(srcdir)/%reldir%/tarot.man: src/tarot-app/main.vala
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot
$(help2man_verbose) ./pre-inst-env help2man tarot > $(srcdir)/%reldir%/tarot.man
$(srcdir)/%reldir%/tarot-status.man: src/tarot-app/tarot_status.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-status
$(help2man_verbose) ./pre-inst-env help2man tarot-status > $@
$(srcdir)/%reldir%/tarot-deal.man: src/tarot-app/tarot_deal.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-deal
$(help2man_verbose) ./pre-inst-env help2man tarot-deal > $@
$(srcdir)/%reldir%/tarot-mcts.man: src/tarot-app/tarot_mcts.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-mcts
$(help2man_verbose) ./pre-inst-env help2man tarot-mcts > $@
$(srcdir)/%reldir%/tarot-stacking.man: src/tarot-app/tarot_stacking.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-stacking
$(help2man_verbose) ./pre-inst-env help2man tarot-stacking > $@
$(srcdir)/%reldir%/tarot-features.man: src/tarot-app/tarot_features.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-features
$(help2man_verbose) ./pre-inst-env help2man tarot-features > $@
$(srcdir)/%reldir%/tarot-cnn-features.man: src/tarot-app/tarot_cnn_features.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-cnn-features
$(help2man_verbose) ./pre-inst-env help2man tarot-cnn-features > $@
$(srcdir)/%reldir%/tarot-cnn.man: src/tarot-app/tarot_cnn.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-cnn
$(help2man_verbose) ./pre-inst-env help2man tarot-cnn > $@
$(srcdir)/%reldir%/tarot-perceptron-bootstrap.man: src/tarot-app/tarot_perceptron_bootstrap.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-perceptron-bootstrap
$(help2man_verbose) ./pre-inst-env help2man tarot-perceptron-bootstrap > $@
# tarot implements the rules of the tarot game
# Copyright (C) 2017, 2018, 2019 Vivien Kraus
# Copyright (C) 2017, 2018, 2019, 2020 Vivien Kraus
# 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
......@@ -18,7 +18,6 @@ TANGLED = \
$(srcdir)/%reldir%/players-and-cards.c \
$(srcdir)/%reldir%/events.c \
$(srcdir)/%reldir%/petit-sec.c \
$(srcdir)/%reldir%/xml.c \
$(srcdir)/%reldir%/duplicate-a-posteriori.c \
$(srcdir)/%reldir%/dumb-ai.c \
$(srcdir)/%reldir%/tarot.rng
......
# tarot implements the rules of the tarot game
# Copyright (C) 2017, 2018, 2019 Vivien Kraus
# Copyright (C) 2017, 2018, 2019, 2020 Vivien Kraus
# 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
......@@ -694,37 +694,6 @@ option.
LANG=C tarot --help
#+END_SRC
** Additional command-line programs
The tarot distribution provides a few other command-line programs:
- =tarot-status= reads a game from the standard input and prints some
informations about the game. There are three kinds of information,
based on the command-line argument:
- if it is =next=, then print the player ID of the next player, or
fails if the game does not have a player to play,
- if it is =at-end=, then it does not print anything but succeeds if
the game is finished, and fails otherwise,
- if it is =score=, then it prints the score for each player, one
row for each player. It fails if the game is not finished,
- if it is =errors=, then it prints the amount of errors that the
players made;
- =tarot-deal= prints a game which has been dealt for all players,
based on the following options:
- =--n-players=: set the number of players,
- =--call-allowed= / =--no-call-allowed=: the game allows a call or
not,
- =--seed=STRING=: set the random seed for the pseudo-random number
generator;
- =tarot-mcts=: reads a game from the standard input, play the next
move as the MCTS, and print the modified game;
- =tarot-stacking=: reads a game from the standard input, play the
next move as the stacking algorithm, and print the modified game;
- =tarot-features=: reads a game from the standard input, and compute
high-level features that can be used for machine learning as an ARFF
file, with a header and a data section. It has an =--encoded=
option to output the features as numerical data (so that it works
better with a regression). The header is distributed with this
package, but the programs will refuse to run if the header is not
compatible with the tarot version.
* Programming with libtarot
Libtarot is the library that you can use in your own program. In
order to use it, you may use the =pkg-config= configuration file that
......@@ -1238,7 +1207,6 @@ Release /object/ that has been allocated with the corresponding
#+begin_deftypefun
An enumeration of errror codes for the game API. It has:
- =TAROT_GAME_OK= = 0, if the operation succeeded;
- =TAROT_GAME_INVXML=, when loading from a document that is not an XML document;
- =TAROT_GAME_INVEV=, when adding an invalid or unexpected event;
- =TAROT_GAME_NA=, when querying game properties that are not set;
- =TAROT_GAME_TOOLATE=, when we set a duplicaté option after it would
......@@ -1421,37 +1389,7 @@ functions.
Return the data associated to the current position of /iterator/, and
advance /iterator/ to the next position.
#+end_deftypefun
#+attr_texinfo: :options {size_t} tarot_game_construct (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment})
#+begin_deftypefun
#+texinfo: @deftypefunx {size_t} tarot_game_iterator_construct (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, const TarotGame *@var{game})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_setup (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, size_t @var{n_players}, int @var{with_call})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_deal (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, TarotPlayer @var{myself}, size_t @var{n_cards}, const TarotCard *@var{cards})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_deal_all (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, size_t @var{n_owners}, const TarotPlayer *@var{owners})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_deal_all_random (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, size_t @var{n_players}, size_t @var{seed_size}, const void *@var{seed})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_bid (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, TarotBid @var{bid})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_decl (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, int @var{slam})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_call (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, TarotCard @var{call})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_dog (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, size_t @var{n_cards}, const TarotCard *@var{cards})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_discard (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, size_t @var{n_cards}, const TarotCard *@var{cards})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_handful (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, size_t @var{n_cards}, const TarotCard *@var{cards})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_card (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, TarotCard @var{card})
#+texinfo: @deftypefunx {size_t} tarot_game_event_construct_copy (size_t @var{maxmem}, char *@var{mem}, size_t *@var{alignment}, const TarotGameEvent *@var{event})
#+texinfo: @deftypefunx {size_t} tarot_counter_construct (size_t @var{maxmem}, char *@var{memout}, size_t *@var{alignment})
If you want to control how memory is allocated, because you have a
very good specific memory allocator you want to use, then you will not
be satisfied by the =tarot_*_alloc= / =tarot_*_dup= family of
functions. This function constructs in place a new object in /mem/
(only used if /maxmem/ is sufficiently large), and return the actual
number of bytes that are needed to hold the game state. The return
value is never 0.
If /maxmem/ is sufficiently large, then /mem/ should be aligned to the
value set in /alignment/ from the previous call. In most cases you
should not worry, since the alignment is never stricter than the
maximum alignment of =max_align_t=.
#+end_deftypefun
** Loading and saving a game with XML
** XML representation of games
#+index: relax-ng
The XML representation of a game is simply the collection of events
that constitue it. Here is the Relax-NG schema for the games:
......@@ -1565,103 +1503,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
The validation for game events is volutarily under-specified, because
it ultimately needs to understand the game rules.
For instance, the package comes with a sample
game:
#+include: ../games/example.xml src xml
So if we encode it as a C string, we can parse it and re-print it.
There can be a couple of differences, like how the namespace is
defined, or the indentation, or the handfuls (empty handfuls are added
in the xml output).
#+name: encode-example-game
#+BEGIN_SRC shell :exports none :results output
sed 's/\\/\\\\/g ; s/"/\\"/g ; s/^/"/g ; s/$/"/g' < ../games/example.xml
#+END_SRC
#+BEGIN_SRC C -i :noweb yes :tangle xml.c
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#include <tarot.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifndef LOCALEDIR
#define LOCALEDIR "/usr/share/locale"
#endif /* NOT LOCALEDIR */
int
main ()
{
static const char *example =
<<encode-example-game()>>;
TarotGame *game;
char *output;
size_t i, len;
size_t n_open_tags = 0;
if (tarot_init (LOCALEDIR) != 0)
{
fprintf (stderr, "Error: could not initialize libtarot.\n");
return EXIT_FAILURE;
}
game = tarot_game_alloc ();
switch (tarot_game_load_from_xml (game, example))
{
case TAROT_GAME_OK:
output = tarot_game_save_to_xml_alloc (game);
printf ("%s\n", output);
len = strlen (output);
for (i = 0; i < len; i++)
{
if (strncmp (output + i, "<", strlen ("<")) == 0)
{
n_open_tags++;
}
}
assert (n_open_tags == 52);
free (output);
break;
case TAROT_GAME_INVXML:
fprintf (stderr, "Error: this is not an XML document.\n");
return EXIT_FAILURE;
break;
case TAROT_GAME_INVEV:
fprintf (stderr, "Error: this is not a valid game.\n");
return EXIT_FAILURE;
break;
case TAROT_GAME_NA:
case TAROT_GAME_TOOLATE:
fprintf (stderr, "Impossible.");
return EXIT_FAILURE;
}
tarot_game_free (game);
tarot_quit ();
return EXIT_SUCCESS;
}
#+END_SRC
#+attr_texinfo: :options {TarotGameError} tarot_game_load_from_xml (TarotGame *@var{game}, const char *@var{input})
#+begin_deftypefun
Erase /game/, and load it from the XML data in utf8-encoded /input/.
#+end_deftypefun
#+attr_texinfo: :options {size_t} tarot_game_save_to_xml (const TarotGame *@var{game}, size_t @var{start}, size_t @var{max}, char *@var{dest})
#+begin_deftypefun
#+texinfo: @deftypefunx {char *} tarot_game_save_to_xml_alloc (const TarotGame *@var{game})
Get the XML document representing /game/ as a string. The =_alloc=
function allocates it with =malloc= (don't forget to call =free=).
The =tarot_game_save_to_xml= function writes it to =dest= (use up to
=max= bytes), trying to put the final NUL character (this is not
possible only if /max/ is 0), and return the number of bytes required
(so you need that value plus one). If /start/ is not 0, then the
representation discards the first /start/ bytes.
#+end_deftypefun
There are no code to export to xml or import from xml as of yet.
** Describing a game
#+attr_texinfo: :options {enum} TarotStep
#+begin_deftp
......@@ -1803,67 +1645,6 @@ operation succeeded and now /game/ knows all the cards of everyone
This operation uses the /n/ bytes of /seed/ to initialize the
pseudo-random number generator.
#+end_deftypefun
** Artificial intelligence through the Monte-Carlo Tree Search
#+attr_texinfo: :options {struct} TarotMcts
#+begin_deftp
A tree structure that holds the MCTS tree. It has a fixed size of
memory available to store the nodes, but since some nodes require more
memory than others (discard and handful nodes hold all cards), it is
not possible to convert it to a maximum number of nodes.
There are a few parameters for the algorithm. All of them have a
default value which is not specified. Reproducibility is thus only
guaranteed with the same minor version of libtarot, if all parameters
are defined manually.
#+end_deftp
#+attr_texinfo: :options enum TarotMctsError
#+begin_deftp
Everything that can happen when populating the MCTS tree:
- =TAROT_MCTS_OK=: no error;
- =TAROT_MCTS_NONEXT=: the game is not expecting a move from a player
(dog);
- =TAROT_MCTS_UNKNOWNNEXT=: the game expects a move from a player
whose cards we don't know;
- =TAROT_MCTS_NODATA=: it was not possible to expand a single node
within the MCTS. Likely cause: the game is corrupted. Other cause:
you have bad luck when imputing the game;
- =TAROT_MCTS_NOMEM=: the memory limit has been reached.
#+end_deftp
#+attr_texinfo: :options {TarotMcts *} tarot_mcts_alloc (size_t @var{maxpool})
#+begin_deftypefun
#+texinfo: @deftypefunx {size_t} tarot_mcts_construct (size_t @var{max_mem}, char *@var{mem}, size_t *@var{alignment}, size_t @var{maxpool})
Allocate a new MCTS tree, that has a memory pool of /maxpool/ bytes.
#+end_deftypefun