Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
ygopro-core
Commits
db66a6db
Commit
db66a6db
authored
Mar 11, 2022
by
salix5
Committed by
GitHub
Mar 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update shuffle_vector() (#437)
parent
9acf492c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
13 deletions
+19
-13
field.cpp
field.cpp
+4
-4
mtrandom.h
mtrandom.h
+15
-9
No files found.
field.cpp
View file @
db66a6db
...
@@ -957,14 +957,14 @@ void field::shuffle(uint8 playerid, uint8 location) {
...
@@ -957,14 +957,14 @@ void field::shuffle(uint8 playerid, uint8 location) {
}
}
}
}
if
(
location
==
LOCATION_HAND
||
!
(
core
.
duel_options
&
DUEL_PSEUDO_SHUFFLE
))
{
if
(
location
==
LOCATION_HAND
||
!
(
core
.
duel_options
&
DUEL_PSEUDO_SHUFFLE
))
{
uint32
s
=
(
u
int32
)
svector
.
size
();
int32
s
=
(
int32
)
svector
.
size
();
if
(
location
==
LOCATION_EXTRA
)
if
(
location
==
LOCATION_EXTRA
)
s
=
s
-
player
[
playerid
].
extra_p_count
;
s
=
s
-
(
int32
)
player
[
playerid
].
extra_p_count
;
if
(
s
>
1
)
{
if
(
s
>
1
)
{
if
(
core
.
duel_options
&
DUEL_OLD_REPLAY
)
if
(
core
.
duel_options
&
DUEL_OLD_REPLAY
)
pduel
->
random
.
shuffle_vector_old
(
svector
);
pduel
->
random
.
shuffle_vector_old
(
svector
,
0
,
s
-
1
);
else
else
pduel
->
random
.
shuffle_vector
(
svector
);
pduel
->
random
.
shuffle_vector
(
svector
,
0
,
s
-
1
);
reset_sequence
(
playerid
,
location
);
reset_sequence
(
playerid
,
location
);
}
}
}
}
...
...
mtrandom.h
View file @
db66a6db
...
@@ -44,20 +44,26 @@ public:
...
@@ -44,20 +44,26 @@ public:
return
result
;
return
result
;
}
}
// Fisher-Yates shuffle
// Fisher-Yates shuffle
v[a]~v[b]
template
<
typename
T
>
template
<
typename
T
>
void
shuffle_vector
(
std
::
vector
<
T
>&
v
)
{
void
shuffle_vector
(
std
::
vector
<
T
>&
v
,
int
a
=
-
1
,
int
b
=
-
1
)
{
int
n
=
(
int
)
v
.
size
();
if
(
a
<
0
)
for
(
int
i
=
0
;
i
<
n
-
1
;
++
i
)
{
a
=
0
;
int
r
=
get_random_integer
(
i
,
n
-
1
);
if
(
b
<
0
)
b
=
(
int
)
v
.
size
()
-
1
;
for
(
int
i
=
a
;
i
<
b
;
++
i
)
{
int
r
=
get_random_integer
(
i
,
b
);
std
::
swap
(
v
[
i
],
v
[
r
]);
std
::
swap
(
v
[
i
],
v
[
r
]);
}
}
}
}
template
<
typename
T
>
template
<
typename
T
>
void
shuffle_vector_old
(
std
::
vector
<
T
>&
v
)
{
void
shuffle_vector_old
(
std
::
vector
<
T
>&
v
,
int
a
=
-
1
,
int
b
=
-
1
)
{
int
n
=
(
int
)
v
.
size
();
if
(
a
<
0
)
for
(
int
i
=
0
;
i
<
n
-
1
;
++
i
)
{
a
=
0
;
int
r
=
get_random_integer_old
(
i
,
n
-
1
);
if
(
b
<
0
)
b
=
(
int
)
v
.
size
()
-
1
;
for
(
int
i
=
a
;
i
<
b
;
++
i
)
{
int
r
=
get_random_integer_old
(
i
,
b
);
std
::
swap
(
v
[
i
],
v
[
r
]);
std
::
swap
(
v
[
i
],
v
[
r
]);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment