Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bandit_Manchot
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
benjamin.sitbon
Bandit_Manchot
Commits
c5f2460f
Commit
c5f2460f
authored
4 years ago
by
benjamin.sitbon
Browse files
Options
Downloads
Patches
Plain Diff
ça marche pas mais ça compile
parent
2908038c
No related branches found
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
display.c
+42
-22
42 additions, 22 deletions
display.c
display.h
+2
-1
2 additions, 1 deletion
display.h
one_armed_bandit.c
+24
-2
24 additions, 2 deletions
one_armed_bandit.c
one_armed_bandit.h
+1
-1
1 addition, 1 deletion
one_armed_bandit.h
wheel.c
+24
-28
24 additions, 28 deletions
wheel.c
wheel.h
+4
-1
4 additions, 1 deletion
wheel.h
with
97 additions
and
55 deletions
display.c
+
42
−
22
View file @
c5f2460f
#include
"display.h"
#include
"display.h"
#include
"one_armed_bandit.h"
// the following global variables are defined for graphical objects only:
// the following global variables are defined for graphical objects only:
// the images size is 104x128 pixels
// the images size is 104x128 pixels
SDL_Window
*
init_display
(){
void
*
display_func
(
void
*
param
){
int
one_arm_width
,
one_arm_height
;
int
one_arm_width
,
one_arm_height
;
SDL_Window
*
window
;
SDL_Window
*
window
;
...
@@ -28,8 +28,34 @@ void *display_func(void *param){
...
@@ -28,8 +28,34 @@ void *display_func(void *param){
&
object_rect
))
!=
NULL
);
&
object_rect
))
!=
NULL
);
object_height
=
object_rect
.
h
/
9
;
object_height
=
object_rect
.
h
/
9
;
return
window
;
}
display_wheel
(
int
pixel
,
int
offset
){
// -------------------------
// example of board display:
// -------------------------
SDL_Rect
src_rect
,
dst_rect
=
object_rect
;
dst_rect
.
h
=
object_height
*
1
.
5
;
// display 1.5 object on screen for a wheel
src_rect
=
dst_rect
;
src_rect
.
x
=
0
;
// src_rect.y is positionned here on the 2nd object of objects.png
//85 + index*104 + 1
src_rect
.
y
=
object_height
*
offset
;
dst_rect
.
x
=
pixel
;
dst_rect
.
y
=
410
-
object_height
/
2
;
// setup the coord. of the icon in the global renderer
SDL_RenderCopy
(
renderer
,
objects_texture
,
&
src_rect
,
&
dst_rect
);
}
void
*
display_func
(
void
*
param
){
printf
(
"
\n
display_func"
);
machine
mas
=
*
((
machine
*
)
param
);
while
(
1
){
SDL_RenderCopy
(
renderer
,
one_arm_texture
,
NULL
,
&
one_arm_rect
);
SDL_RenderCopy
(
renderer
,
one_arm_texture
,
NULL
,
&
one_arm_rect
);
SDL_Rect
coin_rect_pos
=
{
700
,
1020
,
coin_rect
.
w
,
coin_rect
.
h
};
SDL_Rect
coin_rect_pos
=
{
700
,
1020
,
coin_rect
.
w
,
coin_rect
.
h
};
...
@@ -39,21 +65,15 @@ void *display_func(void *param){
...
@@ -39,21 +65,15 @@ void *display_func(void *param){
SDL_RenderCopy
(
renderer
,
coin_texture
,
NULL
,
&
coin_rect_pos
);
SDL_RenderCopy
(
renderer
,
coin_texture
,
NULL
,
&
coin_rect_pos
);
}
}
for
(
int
i
=
0
;
i
<
3
;
i
++
){
display_wheel
(
85
+
104
*
i
+
1
,
mas
.
wheels
[
i
].
current_px
);
}
SDL_RenderPresent
(
renderer
);
SDL_RenderPresent
(
renderer
);
wait_until
(
20
);
wait_until
(
20
);
// -------------------------
// managing events:
// -------------------------
}
SDL_DestroyTexture
(
objects_texture
);
SDL_DestroyTexture
(
one_arm_texture
);
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
window
);
SDL_Quit
();
return
NULL
;
return
NULL
;
}
}
...
...
This diff is collapsed.
Click to expand it.
display.h
+
2
−
1
View file @
c5f2460f
...
@@ -19,7 +19,8 @@ static SDL_Rect object_rect;
...
@@ -19,7 +19,8 @@ static SDL_Rect object_rect;
int
object_height
;
// global for convenience
int
object_height
;
// global for convenience
void
*
display_func
(
void
*
param
);
void
*
display_func
(
void
*
param
);
int
wheel_spin
(
double
offset
,
int
pixel
,
int
time
);
display_wheel
(
int
pixel
,
int
offset
);
SDL_Window
*
init_display
();
// height of one single object
// height of one single object
extern
int
object_height
;
// global for convenience
extern
int
object_height
;
// global for convenience
...
...
This diff is collapsed.
Click to expand it.
one_armed_bandit.c
+
24
−
2
View file @
c5f2460f
...
@@ -7,7 +7,10 @@
...
@@ -7,7 +7,10 @@
#include
<pthread.h>
#include
<pthread.h>
#include
<semaphore.h>
#include
<semaphore.h>
#include
"utilities.h"
#include
"utilities.h"
#include
"display.h"
#include
"one_armed_bandit.h"
#include
"one_armed_bandit.h"
#include
"threads.h"
int
insert_coin
(){
int
insert_coin
(){
...
@@ -34,10 +37,29 @@ wheel create_wheel(int pixel,int speed){
...
@@ -34,10 +37,29 @@ wheel create_wheel(int pixel,int speed){
int
main
()
int
main
()
{
{
pthread_t
threads
[
5
];
SDL_Window
*
window
=
init_display
();
pthread_t
threads
[
4
];
machine
mas
;
mas
.
wheels
[
0
]
=
create_wheel
(
85
,
6
);
mas
.
wheels
[
1
]
=
create_wheel
(
85
+
105
,
4
);
mas
.
wheels
[
2
]
=
create_wheel
(
85
+
104
*
2
+
1
,
2
);
for
(
int
i
=
0
;
i
<
3
;
i
++
){
run_thread
(
&
threads
[
i
],
wheel_func
,
&
mas
.
wheels
[
i
]);
}
display_func
(
&
mas
);
display_func
(
NULL
);
SDL_DestroyTexture
(
objects_texture
);
SDL_DestroyTexture
(
one_arm_texture
);
SDL_DestroyRenderer
(
renderer
);
SDL_DestroyWindow
(
window
);
SDL_Quit
();
SDL_Event
event
;
SDL_Event
event
;
bool
quit
=
false
;
bool
quit
=
false
;
...
...
This diff is collapsed.
Click to expand it.
one_armed_bandit.h
+
1
−
1
View file @
c5f2460f
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include
"wheel.h"
;
#include
"wheel.h"
;
typedef
struct
machine_a_sous
{
typedef
struct
machine_a_sous
{
wheel
*
wheels
;
wheel
wheels
[
WHEEL_NB
]
;
int
player_wallet
;
int
player_wallet
;
int
machine_wallet
;
int
machine_wallet
;
}
machine
;
}
machine
;
...
...
This diff is collapsed.
Click to expand it.
wheel.c
+
24
−
28
View file @
c5f2460f
...
@@ -11,41 +11,37 @@ int get_current_px(){
...
@@ -11,41 +11,37 @@ int get_current_px(){
return
-
1
;
return
-
1
;
}
}
int
wheel_spin
(
double
offset
,
int
pixel
,
int
time
){
// -------------------------
// example of board display:
// -------------------------
SDL_Rect
src_rect
,
dst_rect
=
object_rect
;
dst_rect
.
h
=
object_height
*
1
.
5
;
// display 1.5 object on screen for a wheel
src_rect
=
dst_rect
;
src_rect
.
x
=
0
;
// src_rect.y is positionned here on the 2nd object of objects.png
//85 + index*104 + 1
src_rect
.
y
=
object_height
*
offset
;
dst_rect
.
x
=
pixel
;
dst_rect
.
y
=
410
-
object_height
/
2
;
// setup the coord. of the icon in the global renderer
SDL_RenderCopy
(
renderer
,
objects_texture
,
&
src_rect
,
&
dst_rect
);
wait_until
(
time
);
return
0
;
}
void
*
wheel_func
(
void
*
param
){
void
*
wheel_func
(
void
*
param
){
printf
(
"
\n
wheel_func"
);
wheel
id
=
*
((
wheel
*
)
param
);
wheel
id
=
*
((
wheel
*
)
param
);
while
(
1
){
while
(
1
){
for
(
double
a
=
0
;
a
<
8
.
0
;
a
+=
0
.
1
){
// for(double a = 0; a<8.0; a +=0.1){
wheel_spin
(
a
,
id
.
current_px
,
id
.
speed
);
// wheel_spin(a,id.current_px,id.speed);
wheel_spin_1_tick
(
&
id
);
wait_until
(
wheel_delay_ms
(
id
));
}
}
}
}
int
wheel_spin_1_tick
(
wheel
*
this
){
this
->
current_px
=
(
this
->
current_px
+
2
)
%
896
;
}
int
wheel_delay_ms
(
wheel
this
){
return
this
.
speed
*
2
;
}
int
stop_wheel
(
wheel
this
){
while
(
this
.
current_px
%
128
!=
0
)
{
wheel_spin_1_tick
(
&
this
);
wait_until
(
wheel_delay_ms
(
this
));
}
this
.
speed
=
0
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
wheel.h
+
4
−
1
View file @
c5f2460f
...
@@ -4,6 +4,9 @@ typedef struct roue{
...
@@ -4,6 +4,9 @@ typedef struct roue{
}
wheel
;
}
wheel
;
int
wheel_spin
(
double
offset
,
int
pixel
,
int
time
);
int
set_speed
(
int
s
);
int
set_speed
(
int
s
);
int
get_current_px
();
int
get_current_px
();
void
*
wheel_func
(
void
*
param
);
int
wheel_spin_1_tick
(
wheel
*
this
);
int
wheel_delay_ms
(
wheel
this
);
int
stop_wheel
(
wheel
this
);
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