-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusermove.yml
43 lines (36 loc) · 1.16 KB
/
usermove.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
---
- name: Reset the available moves
set_fact:
available_fields: []
no_log: true
- name: Check which moves are available
set_fact:
available_fields: "{{ available_fields + [item.name] }}"
when: item.value == " "
loop: "{{ board_array }}"
no_log: true
- name: Draw the board
import_tasks: draw.yml
- name: Ask the user for a move
pause:
prompt: "Please select a move from the list: {{ available_fields | string }}: "
register: result
until: result.user_input in available_fields
- name: Set the user selected field to x
set_fact:
"{{ result.user_input }}": x
no_log: true
- name: Draw the board
import_tasks: draw.yml
- name: Check if user has won
fail:
msg: "Congratulations, you have won!"
when:
- "( A0 == 'x' and A1 == 'x' and A2 == 'x' ) or \
( B0 == 'x' and B1 == 'x' and B2 == 'x' ) or \
( C0 == 'x' and C1 == 'x' and C2 == 'x' ) or \
( A0 == 'x' and B0 == 'x' and C0 == 'x' ) or \
( A1 == 'x' and B1 == 'x' and C1 == 'x' ) or \
( A2 == 'x' and B2 == 'x' and C2 == 'x' ) or \
( A0 == 'x' and B1 == 'x' and C2 == 'x' ) or \
( A2 == 'x' and B1 == 'x' and C0 == 'x' )"