-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmastermind-tasks.yml
57 lines (47 loc) · 1.4 KB
/
mastermind-tasks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
- name: Ask.
pause:
prompt: "What is your guess?"
register: __guesses
- set_fact:
guesses: "{{ __guesses.user_input.split(',') }}"
- name: Verify user input.
block:
- assert:
that: (guesses|length) == 4
quiet: yes
- block:
- assert:
that:
- guesses[0] in colours
- guesses[1] in colours
- guesses[2] in colours
- guesses[3] in colours
quiet: yes
- include_tasks: bull-or-cow.yml
- name: Increase turn number.
set_fact:
turns: "{{ turns | int + 1 }}"
- name: Register input.
set_fact:
input_history: "{{ input_history + [ guesses ] }}"
- debug:
msg: |
{% for input in input_history %}
Turn {{ loop.index }}: {% for guesses in input %}|{{ guesses|center(8) }}{% if loop.last %}|
{% endif %}{% endfor %}
{% endfor %}
----
{{ bulls }} bulls and {{ cows }} cows
rescue:
- name: Error with colours.
debug:
msg: "Sorry, only {{ colours }} are allowed."
rescue:
- name: Error with colours.
debug:
msg: "Your guesses should be structured as four components list separated by comma."
- include_tasks: mastermind-tasks.yml
when:
- bulls|int != 4
- turns|int != maxturns