Skip to content

Commit c2ffdce

Browse files
committed
2 parents 52ab1df + 18492fa commit c2ffdce

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# DecisionMakingProblems
22

3-
[![Build Status](https://travis-ci.com/SidhartK/DecisionMakingProblems.jl.svg?branch=master)](https://travis-ci.com/SidhartK/DecisionMakingProblems.jl)
4-
[![Coverage](https://codecov.io/gh/SidhartK/DecisionMakingProblems.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/SidhartK/DecisionMakingProblems.jl)
5-
[![Coverage](https://coveralls.io/repos/github/SidhartK/DecisionMakingProblems.jl/badge.svg?branch=master)](https://coveralls.io/github/SidhartK/DecisionMakingProblems.jl?branch=master)
63
[![Docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://algorithmsbooks.github.io/DecisionMakingProblems.jl/)
74

8-
Specifically it allows the user to run various environments that are present in Algorithms for Decision Making by Mykel Kochenderfer, Tim Wheeler and Kyle Wray.
5+
This package contains various decision problem environments from [Algorithms for Decision Making](https://algorithmsbook.com/) by Mykel Kochenderfer, Tim Wheeler and Kyle Wray.
96

107
## Installation
118

129
Start Julia and run the following command:
1310

1411
```julia
15-
Pkg.add("DecisionMakingProblems")
12+
] add https://github.com/algorithmsbooks/DecisionMakingProblems.jl
1613
```
1714

1815
## Usage
@@ -26,3 +23,5 @@ using DecisionMakingProblems
2623
## Credits
2724

2825
Contributors to this package include Sidhart Krishnan, Tim Wheeler, and Mykel Kochenderfer.
26+
27+
The 2048 implementation was translated from [a C++ implementation](https://github.com/nneonneo/2048-ai) by Robert Xiao.

src/mdp/2048.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,44 +50,46 @@ const TWENTY_FORTY_EIGHT_MOVE_STRINGS = ["LEFT", "DOWN", "RIGHT", "UP"]
5050
γ::Float64 = 1.0
5151
end
5252

53-
function transition(s::Board, a::TwentyFortyEightAction)
53+
function transition(mdp::TwentyFortyEight, s::Board, a::TwentyFortyEightAction)
5454
s′ = move(s, a)
55-
if s′ == s
55+
if s′ == s # terminal state or illegal action
5656
return s′
5757
end
5858
s′ = insert_tile_rand(s′, draw_tile())
5959
return s′
6060
end
6161

62-
function reward(s::Board, a::TwentyFortyEightAction)
62+
function reward(mdp::TwentyFortyEight, s::Board, a::TwentyFortyEightAction)
6363
s′ = move(s, a)
64-
if s′ == s
64+
if s′ == s # terminal state or illegal action
6565
return -1.0
6666
end
6767
s′ = insert_tile_rand(s′, draw_tile())
6868
return score_board(s′) - score_board(s)
6969
end
7070

71+
function transition_and_reward(mdp::TwentyFortyEight, s::Board, a::TwentyFortyEightAction)
72+
s′ = move(s, a)
73+
if s′ == s # terminal state or illegal action
74+
return (s′, -1.0)
75+
end
76+
s′ = insert_tile_rand(s′, draw_tile())
77+
r = score_board(s′) - score_board(s)
78+
return (s′, r)
79+
end
80+
7181

7282
function MDP(mdp::TwentyFortyEight; γ::Float64=mdp.γ)
7383
return MDP(
7484
γ,
7585
nothing, # no ordered states
7686
DIRECTIONS,
7787
nothing, # no probabilistic transition function
78-
(s,a) -> reward(s, a),
79-
(s, a)->begin
80-
s′ = transition(s, a)
81-
r = reward(s, a)
82-
return (s′, r)
83-
end
88+
(s,a) -> reward(mdp, s, a),
89+
(s, a)-> transition_and_reward(mdp, s,a)
8490
)
8591
end
8692

87-
88-
89-
90-
9193
"""
9294
Print out a 2048 state.
9395
"""

0 commit comments

Comments
 (0)