-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7692e52
Showing
41 changed files
with
3,576 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Chia Dev Sandbox | ||
|
||
![Chia Logo](intro/static/img/chia-logo.svg) | ||
|
||
Here you can experiment with smart contracts and coloured coins using Chialisp, a powerful and | ||
secure language for smart money based on LISP. | ||
|
||
All of the necessary tools like `chia` and `cdv` are already installed, and a number of examples | ||
can be found in the [examples](examples) folder. | ||
|
||
To view this page again at any time, open [README.md](README.md) and hit Ctrl+Shift+V. | ||
|
||
1. ### [Getting Started](intro/01-Getting-Started.md) | ||
2. ### [Creating a Coloured Coin](intro/02-Creating-a-Coloured-Coin.md) | ||
3. ### [Deploying to Testnet](intro/03-Deploying-to-testnet.md) | ||
4. ### [Deploying to Mainnet](intro/04-Deploying-to-mainnet.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__pycache__ | ||
*.hex | ||
checkers.db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# chia-checkers | ||
|
||
Theory of operation: | ||
|
||
This contract creates a playable game of checkers which carries some attributes | ||
of the game in its solution so that they can be picked out by another | ||
participant, including the identity of the coin that launched it, which must | ||
be restated to interact with it. | ||
|
||
The game is a function that accepts 3 arguments, for a normal move: | ||
|
||
```(() (move) (("launcher" . launcher-coin) ("board" . board)))``` | ||
|
||
The game uses a board state like this: | ||
|
||
```(black-to-move king-mask red-mask black-mask)``` | ||
|
||
Where black-to-move is treated as boolean and the rest are integers where each bit | ||
`1 << ((8 * x) + y)` represents that the mask contains a true value at (`x`,`y`). | ||
|
||
And it is curried in at each stage. The copy in the third parameter, which | ||
as I understand things is intended to be an alist containing data we want to | ||
communicate to other users should contain the identity of the original parent | ||
coin, "launcher", which will be verified and the board state "board", which is | ||
also verified before any operation. The next move is emitted with an AGG_SIG_ME | ||
for the player who's turn it was, so that turn order is enforced. | ||
|
||
A move is a number as in make_move_sexp. | ||
|
||
When no moves can be taken by the next player, the winning player may win the | ||
game by passing () for move and the chia is given to that player. | ||
|
||
The first argument may be given as "simulate" in which case, the contract can | ||
be asked to give its conception of the next puzzle hash and the board state | ||
that goes with it, given a move. This is used in a rudimentary way for driver | ||
code to be able to ask the contract what will happen when a move is requested. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
( | ||
(defconstant emptyBoard (1 0 0xa040a040a040a040 0x205020502050205)) | ||
|
||
(defun board$next (b) (f b)) | ||
(defun board$king (b) (f (r b))) | ||
(defun board$red (b) (f (r (r b)))) | ||
(defun board$black (b) (f (r (r (r b))))) | ||
|
||
(defun checkerAt1 (mask b) | ||
(if (logand mask (board$red b)) | ||
(list (if (logand mask (board$king b)) (makeKing 0) (makePawn 0))) | ||
(if (logand mask (board$black b)) | ||
(list (if (logand mask (board$king b)) (makeKing 1) (makePawn 1))) | ||
(quote ()) | ||
) | ||
) | ||
) | ||
(defun checkerAt (pt b) (checkerAt1 (maskFor pt) b)) | ||
|
||
(defun removeChecker1 (mask b) | ||
(list | ||
(board$next b) | ||
(logxor (board$king b) (if (logand mask (board$king b)) mask 0)) | ||
(logxor (board$red b) (if (logand mask (board$red b)) mask 0)) | ||
(logxor (board$black b) (if (logand mask (board$black b)) mask 0))) | ||
) | ||
(defun removeChecker (pt b) (removeChecker1 (maskFor pt) b)) | ||
|
||
(defun inBounds (X Y) (* (* (+ (> X 0) (= X 0)) (> 8 X)) (* (+ (> Y 0) (= Y 0)) (> Y y)))) | ||
|
||
(defun addChecker2 (king red black b) | ||
(list (board$next b) (logior king (board$king b)) (logior red (board$red b)) (logior black (board$black b)))) | ||
(defun addChecker1 (mask ch b) | ||
(addChecker2 (if (isKing ch) mask 0) (if (checkerColor ch) 0 mask) (if (checkerColor ch) mask 0) b)) | ||
(defun addChecker (pt ch b) (addChecker1 (maskFor pt) ch b)) | ||
|
||
(defun forward (color dy) (i color (> dy 0) (> 0 dy))) | ||
(defun kingRow (color) (i color 7 0)) | ||
|
||
(defun listCheckersWithColor2 (head rest) (if head (c head rest) rest)) | ||
(defun listCheckersWithColor1 (n color b chq) | ||
(listCheckersWithColor2 | ||
(if chq | ||
(if (eq (colorOfMaybeChecker chq) (just color)) | ||
(c (moddiv n 8) (fromJust chq)) | ||
() | ||
) | ||
() | ||
) | ||
(listCheckersWithColor (+ n 1) color b)) | ||
) | ||
|
||
(defun listCheckersWithColor (n color b) | ||
(if (> n 63) | ||
() | ||
(listCheckersWithColor1 n color b (checkerAt (moddiv n 8) b)) | ||
) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
( | ||
(defun makeKing (color) (c 1 color)) | ||
(defun makePawn (color) (c 0 color)) | ||
(defun isKing (checker) (= (f checker) 1)) | ||
|
||
(defun checkerColor (ch) (r ch)) | ||
(defun otherColor (color) (if (= color 0) 1 0)) | ||
|
||
(defun colorOfMaybeChecker (mCh) (if mCh (just (checkerColor (fromJust mCh))) ())) | ||
) |
Oops, something went wrong.