Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wordle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
repos.tanguy.cavagna
sequencial programming
wordle
Commits
444b056a
Commit
444b056a
authored
2 years ago
by
tanguy.cavagna
Browse files
Options
Downloads
Patches
Plain Diff
Working project
parent
e6fd7b64
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
conf.h
+2
-1
2 additions, 1 deletion
conf.h
ui/ui.c
+30
-4
30 additions, 4 deletions
ui/ui.c
ui/ui.h
+14
-3
14 additions, 3 deletions
ui/ui.h
wordle/wordle.c
+29
-3
29 additions, 3 deletions
wordle/wordle.c
with
75 additions
and
11 deletions
conf.h
+
2
−
1
View file @
444b056a
...
...
@@ -4,9 +4,10 @@
// Game setup
#define TRIES_COUNT 6
#define WORD_LENGHT 5
#define VERSUS_TURN_COUNT 2
// Enums
typedef
enum
Gamemode
{
SOLO
,
VERSUS
,
TOOL_ASSISTED
}
Gamemode
;
typedef
enum
Pattern
{
WRONG
,
MISPLACED
,
CORRECT
,
NAP
}
Pattern
;
// NAP => Not A Pattern (Only used when computing all possible patterns)
#endif
\ No newline at end of file
#endif
This diff is collapsed.
Click to expand it.
ui/ui.c
+
30
−
4
View file @
444b056a
#include
"ui.h"
#include
<curses.h>
#define MENU_MAX 4
#define TITLE_Y_OFFSET 2
...
...
@@ -282,7 +283,7 @@ void update_tool(int count, char words[count][WORD_LENGHT + 1], double *entropie
wrefresh
(
tool
);
}
void
show_gameboard
(
int
tries_count
,
int
word_length
,
char
**
tries
,
Pattern
**
patterns
,
int
score
)
{
void
show_gameboard
(
int
tries_count
,
int
word_length
,
char
**
tries
,
Pattern
**
patterns
,
int
*
score
s
,
Gamemode
mode
,
bool
p2_turn
,
int
current_turn
)
{
for
(
int
i
=
0
;
i
<
tries_count
;
i
++
)
{
// Draw current try letters
for
(
int
j
=
0
;
j
<
word_length
;
j
++
)
{
...
...
@@ -304,8 +305,33 @@ void show_gameboard(int tries_count, int word_length, char **tries, Pattern **pa
}
}
move
(
GAMEBOARD_Y_OFFSET
-
2
-
menu_offset_modifer
()
+
5
,
TERM_MID_COLS
-
word_length
-
3
);
printw
(
"Score: %d"
,
score
);
if
(
mode
==
VERSUS
)
{
move
(
GAMEBOARD_Y_OFFSET
,
TERM_MID_COLS
-
word_length
);
printw
(
"Turn: %d/%d"
,
current_turn
,
VERSUS_TURN_COUNT
);
if
(
!
p2_turn
)
attron
(
COLOR_PAIR
(
GREEN_PAIR
));
move
(
GAMEBOARD_Y_OFFSET
-
2
-
menu_offset_modifer
()
+
5
,
TERM_MID_COLS
-
word_length
-
10
);
printw
(
"Score P1: %d"
,
scores
[
0
]);
attroff
(
COLOR_PAIR
(
GREEN_PAIR
));
if
(
p2_turn
)
attron
(
COLOR_PAIR
(
GREEN_PAIR
));
move
(
GAMEBOARD_Y_OFFSET
-
2
-
menu_offset_modifer
()
+
5
,
TERM_MID_COLS
-
word_length
+
8
);
printw
(
"Score P2: %d"
,
scores
[
1
]);
attroff
(
COLOR_PAIR
(
GREEN_PAIR
));
}
else
{
move
(
GAMEBOARD_Y_OFFSET
-
2
-
menu_offset_modifer
()
+
5
,
TERM_MID_COLS
-
word_length
);
printw
(
"Score: %d"
,
scores
[
0
]);
}
refresh
();
}
\ No newline at end of file
}
void
show_winner
(
bool
p2_turn
,
int
*
scores
)
{
move
(
GAMEBOARD_Y_OFFSET
+
15
,
TERM_MID_COLS
-
13
);
printw
(
"Winner: %s with %d points !"
,
p2_turn
?
"P2"
:
"P1"
,
p2_turn
?
scores
[
1
]
:
scores
[
0
]);
}
This diff is collapsed.
Click to expand it.
ui/ui.h
+
14
−
3
View file @
444b056a
...
...
@@ -118,8 +118,19 @@ void update_tool(int count, char words[count][WORD_LENGHT + 1], double *entropie
* @param word_length
* @param tries
* @param patterns
* @param score
* @param scores
* @param mode
* @param p2_turn
* @param current_turn
*/
void
show_gameboard
(
int
tries_count
,
int
word_length
,
char
**
tries
,
Pattern
**
patterns
,
int
score
);
void
show_gameboard
(
int
tries_count
,
int
word_length
,
char
**
tries
,
Pattern
**
patterns
,
int
*
score
s
,
Gamemode
mode
,
bool
p2_turn
,
int
current_turn
);
#endif
\ No newline at end of file
/**
* @brief Show the winner
*
* @param p2_turn
* @param scores
*/
void
show_winner
(
bool
p2_turn
,
int
*
scores
);
#endif
This diff is collapsed.
Click to expand it.
wordle/wordle.c
+
29
−
3
View file @
444b056a
#include
"wordle.h"
#include
<curses.h>
#include
<stdlib.h>
//==========================
// PRIVATE
...
...
@@ -6,6 +8,9 @@
Gamemode
mode
;
bool
_game_finished
=
false
;
int
score
=
0
;
int
*
scores
;
bool
p2_turn
=
false
;
int
turn
=
0
;
char
**
tries
;
char
*
chosen_word
;
Pattern
**
patterns
;
...
...
@@ -30,8 +35,8 @@ void render_game() {
draw_title
(
COMPUTER_TITLE_ID
);
break
;
}
show_gameboard
(
TRIES_COUNT
,
WORD_LENGHT
,
tries
,
patterns
,
score
);
show_gameboard
(
TRIES_COUNT
,
WORD_LENGHT
,
tries
,
patterns
,
score
s
,
mode
,
p2_turn
,
turn
);
move
(
LINES
-
2
,
COLS
-
10
);
}
...
...
@@ -108,9 +113,11 @@ void initialize_game() {
current_try_id
=
0
;
current_try_letter_id
=
0
;
score
=
0
;
scores
=
calloc
(
2
,
sizeof
(
int
));
// Tries and answer setup
set_answer
(
get_random_word
());
mvprintw
(
30
,
30
,
"%s"
,
chosen_word
);
tries
=
calloc
(
TRIES_COUNT
,
sizeof
(
char
*
));
patterns
=
malloc
(
sizeof
(
Pattern
*
)
*
TRIES_COUNT
);
...
...
@@ -127,6 +134,8 @@ void destroy_game() {
if
(
mode
==
TOOL_ASSISTED
)
destroy_tool
();
free
(
scores
);
for
(
int
i
=
0
;
i
<
TRIES_COUNT
;
i
++
)
{
free
(
tries
[
i
]);
free
(
patterns
[
i
]);
...
...
@@ -142,8 +151,25 @@ void restart_game() {
init_tool
();
}
score
+=
(
TRIES_COUNT
-
current_try_id
)
*
10
;
// Versus mode scores or solo score
if
(
mode
==
VERSUS
)
{
if
(
turn
>=
VERSUS_TURN_COUNT
)
{
show_winner
(
p2_turn
,
scores
);
getch
();
terminate_game
();
return
;
}
scores
[
p2_turn
]
+=
(
TRIES_COUNT
-
current_try_id
)
*
10
;
p2_turn
=
!
p2_turn
;
if
(
!
p2_turn
)
turn
++
;
}
else
scores
[
0
]
+=
(
TRIES_COUNT
-
current_try_id
)
*
10
;
set_answer
(
get_random_word
());
mvprintw
(
30
,
30
,
"%s"
,
chosen_word
);
current_try_id
=
0
;
current_try_letter_id
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment