Skip to content

Instantly share code, notes, and snippets.

@allen-hsu
Created April 1, 2018 09:05
Show Gist options
  • Save allen-hsu/689dc665cf66b519c45ff098baaecd97 to your computer and use it in GitHub Desktop.
Save allen-hsu/689dc665cf66b519c45ff098baaecd97 to your computer and use it in GitHub Desktop.
//Classes
//Record Studuent pick.
//Cal Result
//Studuent Pick Class(Not Pick)
//Pick End Time.
//Query Time
pragma solidity ^0.4.8;
import "https://github.com/OpenZeppelin/zeppelin-solidity/contracts/math/SafeMath.sol";
contract PickClass {
using SafeMath for uint;
address[] private pickClassStudents;
address[] private chosedClassStudents;
mapping(address => bool) chosed;
mapping(address => bool) picked;
address owner;
uint private classMaxStudent = 2;
uint private currentRandomLength;
uint private test;
modifier isValidPick() {
require(!picked[msg.sender]);
_;
}
modifier isOwner() {
require(msg.sender == owner);
_;
}
function PickClass() public {
owner = msg.sender;
//it's for test
pickClassStudents.push(0x0);
pickClassStudents.push(0x1);
pickClassStudents.push(0x2);
pickClassStudents.push(0x3);
pickClassStudents.push(0x4);
pickClassStudents.push(0x5);
}
function pickClass() isValidPick public {
pickClassStudents.push(msg.sender);
picked[msg.sender] = true;
}
function calClassResult() isOwner public {
//Random
currentRandomLength = pickClassStudents.length;
uint pickStudentsLength = pickClassStudents.length;
for(int i = 0; i < classMaxStudent; ++i) {
}
// test = chosedClassStudents.length;
// while(test < classMaxStudent) {
// uint chosedRandom = random(0, currentRandomLength);
// chosedClassStudents.push(pickClassStudents[chosedRandom]);
// (pickClassStudents[chosedRandom], pickClassStudents[pickStudentsLength]) = (pickClassStudents[pickStudentsLength], pickClassStudents[chosedRandom]);
// currentRandomLength.sub(1);
// test = chosedClassStudents.length;
// }
}
function isChosed() public view returns(bool) {
return chosed[msg.sender];
}
function checkResult() public view returns(address[]) {
return chosedClassStudents;
}
function checkPickStudent() public view returns(address[]) {
return pickClassStudents;
}
function random(uint min, uint max) private constant returns(uint) {
return now % (max - min) + min;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment