Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit 882fe44

Browse files
committed
Merge branch 'dev'
2 parents b12e5a5 + db0004f commit 882fe44

File tree

219 files changed

+17495
-7701
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+17495
-7701
lines changed

.coveragerc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[run]
2+
omit =
3+
env/*
4+
project/bots_battle.py
5+
project/game/ai/configs/*
6+
project/game/bots_battle/*
7+
project/settings/*
8+
*/test_*.py
9+
*/__init__.py
10+
project/reproducer.py
11+
project/main.py
12+
project/tenhou/*
13+
project/utils/statistics.py
14+
project/utils/logger.py
15+
project/conftest.py
16+
project/utils/settings_handler.py
17+
project/game/client.py
18+
project/system_testing/generate_tests.py
19+
project/system_testing/generate_documentation.py
20+
project/system_testing/cases.py
21+
project/system.py

.flake8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
[flake8]
2+
ignore = E203, E266, E501, W503
23
max-line-length = 120
3-
exclude = *settings.py,tests_validate_hand.py
4+
select = B,C,E,F,W,T4,B9
5+
exclude = project/settings/*,tests_validate_hand.py,project/system_testing/cases.py,project/system_testing/test_system.py

.github/workflows/pythonapp.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Mahjong bot
2+
3+
on:
4+
push:
5+
branches: [master, dev]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python 3.8
15+
uses: actions/setup-python@v1
16+
with:
17+
python-version: '3.8'
18+
- name: Install libs
19+
run: pip install -r requirements/lint.txt
20+
- name: Lint files
21+
run: make lint
22+
coverage:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- name: Set up Python 3.8
27+
uses: actions/setup-python@v1
28+
with:
29+
python-version: '3.8'
30+
- name: Install libs
31+
run: pip install -r requirements/lint.txt
32+
- name: Generate coverage report
33+
run: make tests_coverage
34+
- name: Deploy to GitHub Pages
35+
uses: JamesIves/[email protected]
36+
with:
37+
GITHUB_TOKEN: ${{ secrets.PASSWORD }}
38+
BRANCH: gh-pages # The branch the action should deploy to.
39+
FOLDER: htmlcov # The folder the action should deploy.
40+
CLEAN: true # Automatically remove deleted files from the deploy branch
41+
tests:
42+
runs-on: ubuntu-latest
43+
strategy:
44+
matrix:
45+
python-version: [3.7, 3.8, 3.9]
46+
steps:
47+
- uses: actions/checkout@v2
48+
- name: Set up Python ${{ matrix.python-version }}
49+
uses: actions/setup-python@v1
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
- name: Install libs
53+
run: pip install -r requirements/dev.txt
54+
- name: Run tests
55+
run: make tests

.gitignore

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
.idea
22
env
33

4+
failed_*.txt
5+
46
*.py[cod]
57
__pycache__
68
.DS_Store
9+
.pytest_cache
710
logs
8-
project/settings_local.py
9-
project/*_settings.py
11+
project/settings/*
12+
!project/settings/__init__.py
13+
!project/settings/base.py
1014
project/game/ai/common
1115

12-
tests_validate_hand.py
16+
test_validate_hand.py
1317
loader.py
14-
socket_mock.py
1518
*.db
1619
temp
1720
*.log
21+
seeds.txt
1822

1923
project/game/data/*
2024
project/analytics/data/*
2125

26+
project/battle_results/**/*
27+
*.tar.gz
28+
2229
# temporary files
2330
experiments
2431

2532
*.prof
26-
profile.py
33+
profile.py
34+
35+
.coverage
36+
htmlcov

.travis.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM pypy:3.7-7.3.2-slim
2+
3+
RUN useradd -ms /bin/bash docker-user
4+
5+
WORKDIR /app/
6+
7+
COPY requirements /requirements
8+
RUN pip install --no-cache-dir -r /requirements/dev.txt
9+
10+
COPY ./project .
11+
12+
USER docker-user

LICENSE.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
MIT License
22

3-
Copyright (c) [2016] [Alexey Lisikhin]
4-
53
Permission is hereby granted, free of charge, to any person obtaining a copy
64
of this software and associated documentation files (the "Software"), to deal
75
in the Software without restriction, including without limitation the rights

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
MAKE_FILE_PATH=$(abspath $(lastword $(MAKEFILE_LIST)))
2+
CURRENT_DIR=$(dir $(MAKE_FILE_PATH))
3+
4+
check: generate_system_tests format lint tests
5+
6+
format:
7+
isort project/*
8+
black project/*
9+
10+
lint:
11+
isort --check-only project/*
12+
black --check project/*
13+
flake8 project/*
14+
15+
generate_system_tests:
16+
python project/system.py
17+
18+
tests:
19+
PYTHONPATH=./project pytest -n 4
20+
21+
tests_coverage:
22+
PYTHONPATH=./project pytest --cov=. --cov-report html -n 4
23+
24+
build_docker:
25+
docker build -t mahjong_bot .
26+
27+
GAMES=1
28+
run_battle:
29+
docker run -u `id -u` -it --rm \
30+
--cpus=".9" \
31+
-v "$(CURRENT_DIR)project/:/app/" \
32+
-v /dev/urandom:/dev/urandom \
33+
mahjong_bot pypy3 bots_battle.py -g $(GAMES) $(ARGS)
34+
35+
run_on_tenhou:
36+
docker-compose up
37+
38+
archive_replays:
39+
tar -czvf "logs-$(shell date '+%Y-%m-%d-%H-%M').tar.gz" -C ./project/battle_results/logs/ .
40+
tar -czvf "replays-$(shell date '+%Y-%m-%d-%H-%M').tar.gz" -C ./project/battle_results/replays/ .

README.md

Lines changed: 26 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[![Build Status](https://travis-ci.org/MahjongRepository/tenhou-python-bot.svg?branch=master)](https://travis-ci.org/MahjongRepository/tenhou-python-bot)
1+
![Build](https://github.com/MahjongRepository/tenhou-python-bot/workflows/Mahjong%20bot/badge.svg) [[Tests coverage]](http://mahjongrepository.github.io/tenhou-python-bot/)
22

3-
For now only **Python 3.5+** is supported.
3+
Bot was tested with Python 3.6+ and PyPy3, we are not supporting Python 2.
44

55
# What do we have here?
66

@@ -14,124 +14,42 @@ You can find it here: https://github.com/MahjongRepository/mahjong
1414

1515
For research purposes we built a simple bot to play riichi mahjong on tenhou.net server.
1616

17-
### 0.4.0 version
17+
Here you can read about bot played games statistic: [versions history](doc/versions.md)
1818

19-
Version with various improvements in hand building and melds calling.
20-
21-
This version had played ~1000 games (hanchans) and achieved fourth dan (四段) a couple of times.
22-
23-
Stable rank was a second dan (二段) and stable rate was ~R1600.
24-
25-
Stat:
26-
27-
| | Result |
28-
| --- | --- |
29-
| Average position | 2.53 |
30-
| Win rate | 19.21% |
31-
| Feed rate | 11.78% |
32-
| Riichi rate | 18.48% |
33-
| Call rate | 24.41% |
34-
35-
| Places | |
36-
| --- | --- |
37-
| First | 20.92% |
38-
| Second | 27.46% |
39-
| Third| 30.17% |
40-
| Fourth | 21.45% |
41-
| Bankruptcy | 6.19% |
42-
43-
The number of fourth places was decreased.
44-
45-
### 0.3.2 version
46-
47-
Version with various improvements.
48-
49-
This version had played 600 games (hanchans) and achieved fourth dan (四段) once.
50-
51-
Stable rank was a first dan (初段).
52-
53-
Stat:
54-
55-
| | Result |
56-
| --- | --- |
57-
| Average position | 2.53 |
58-
| Win rate | 19.97% |
59-
| Feed rate | 10.88% |
60-
| Riichi rate | 15.80% |
61-
| Call rate | 36.39% |
62-
63-
| Places | |
64-
| --- | --- |
65-
| First | 22.41% |
66-
| Second | 25.52% |
67-
| Third| 28.28% |
68-
| Fourth | 23.79% |
69-
| Bankruptcy | 4.48% |
70-
71-
### 0.2.5 version
72-
73-
This version is much smarter than 0.0.x versions. It can open hand, go to defence and build hand effective (all supported features you can find in releases description).
74-
75-
This version had played 375 games (hanchans) and achieved second dan (二段).
76-
77-
Rate was somewhere around R1500.
78-
79-
Stat:
80-
81-
| | Result |
82-
| --- | --- |
83-
| Average position | 2.65 |
84-
| Win rate | 18.60% |
85-
| Feed rate | 10.59% |
86-
| Riichi rate | 15.64% |
87-
| Call rate | 34.89% |
88-
89-
### 0.0.5 version
19+
# For developers
9020

91-
It can reach a tempai and call a riichi. It doesn't know about dora, yaku, defence and etc.
92-
Only about tempai and riichi so far.
21+
## How to run it?
9322

94-
This version had played 335 games (hanchans) and achieved only first dan (初段) on the tenhou.net so far
95-
(and lost it later, and achieved it again...).
23+
1. `pip install -r requirements/lint.txt`
24+
1. Run `cd project && python main.py` it will connect to the tenhou.net and will play a game.
9625

97-
Rate was somewhere around R1350.
26+
## How to run bot battle with pypy
9827

99-
Stat:
28+
To make it easier run bot vs bot battles we prepared PyPy3 Docker container.
10029

101-
| | Result |
102-
| --- | --- |
103-
| Average position | 2.78 |
104-
| Win rate | 20.73% |
105-
| Feed rate | 19.40% |
106-
| Riichi rate | 36.17% |
107-
| Call rate | 0% |
30+
Run the game locally:
10831

109-
So, even with the current simple logic it can play and win.
32+
1. [Install Docker](https://docs.docker.com/get-docker/)
33+
1. Run `make build_docker`
34+
1. Run `make GAMES=1 run_battle` it will play one game locally. Logs and replays will be stored in `bots_battle` folder.
11035

111-
# For developers
36+
Run bots with enabled decision logger (use it only for debug, since it harms performance):
37+
1. Run `make GAMES=1 ARGS=--logs run_battle`
11238

113-
## How to run it?
39+
## Run multiple bots to play one game
11440

115-
1. `pip install -r requirements.txt`
116-
2. Run `python main.py` it will connect to the tenhou.net and will play a game
41+
1. [Install Docker](https://docs.docker.com/get-docker/) and [Install Docker Compose](https://docs.docker.com/compose/install/)
42+
1. Run `make build_docker`
43+
1. Put bot configs to `project/settings/`. By default we are looking for these configs: `bot_1_settings.py`, `bot_2_settings.py`, `bot_3_settings.py`, `bot_4_settings.py`, `bot_5_settings.py`. Why 5 settings? Because tenhou doesn't start 2+ game in the custom lobby if you are running only 4 bots.
44+
1. Run `make run_on_tenhou`
11745

11846
## Configuration instructions
11947

120-
1. Put your own settings to the `project/settings_local.py` file.
121-
They will override settings from default `settings.py` file
122-
2. Also you can override some default settings with command argument.
123-
Use `python main.py -h` to check all available commands
124-
125-
## Implement your own AI
126-
127-
https://github.com/MahjongRepository/tenhou-python-bot/wiki/Implement-AI
128-
129-
## Round reproducer
130-
131-
https://github.com/MahjongRepository/tenhou-python-bot/wiki/Round-reproducer
48+
1. Put your own settings to the `project/settings/settings_local.py` file.
49+
They will override settings from default `settings/base.py` file.
50+
1. Also, you can override some default settings with command arguments.
51+
Use `python main.py -h` to check all available commands.
13252

133-
## Contribution to the project
53+
## Game reproducer
13454

135-
All PRs are welcomed anytime. Currently the project is in early stage and
136-
I'm working on the different parts of it in the same time, so before making any
137-
big changes it's better to check with me to avoid code duplication.
55+
It can be useful to debug bot errors or strange discards: [game reproducer](doc/reproducer.md)

0 commit comments

Comments
 (0)