Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit386b811

Browse files
committed
Computer now sometimes places 2s
1 parent16e3360 commit386b811

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

‎10.hs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ enumerateboard b = zip [1..] (concat b)
8484
cturn:: [[Int]]->StdGen-> ([[Int]],Int)
8585
cturn b g=
8686
let
87+
r= random1or2 g
8788
xs= zeroIndices b
8889
upperbound=length (xs)
8990
rs= randomRs (0, upperbound-1) g
@@ -92,7 +93,17 @@ cturn b g =
9293
s=length b
9394
index= mapback x s
9495
in
95-
(replace2d index1 b, x)
96+
-- Replace the random 0 with the random 1 or 2.
97+
-- Return the updated board as well as the updated index.
98+
(replace2d index r b, x)
99+
100+
-- Returns 1 or 2.
101+
-- There is an 80% chance that you'll get 1.
102+
random1or2::StdGen->Int
103+
random1or2 g=let
104+
rs= randomRs (0::Int,9::Int) g
105+
r= rs!!0
106+
inif r>7then2else1-- [8,9] is 20% of [0..9], so 20% chance of getting a 2.
96107

97108
-- Replace item at (row, col) with value in 2d list.
98109
replace2d:: (Int,Int)->a-> [[a]]-> [[a]]

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Choose a direction - up, down, left or right, by entering the corresponding wasd
3535
Two things will now happen.
3636
One: the pieces on the board slide in the direction of your choice.
3737
And two: the computer places a new piece on the board, indicated by an asterisk.
38-
For example, after entering`w` for up:
38+
This new piece will usually be a`1`, but sometimes you'll get a sneaky`2`.
39+
For example, after entering`w` for up, you might get:
3940

4041
```
4142
. 1 . . 1*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp