Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More components! #1

Open
zac-garby opened this issue Oct 14, 2017 · 4 comments
Open

More components! #1

zac-garby opened this issue Oct 14, 2017 · 4 comments

Comments

@zac-garby
Copy link
Owner

Implement any components you want, really. If they work, I'll probably accept a PR :)

@more-coffee-more-code
Copy link

I would like to contribute :)

@zac-garby
Copy link
Owner Author

Cool :)

@pszczolas
Copy link

Hello, I wanted to implement xor gate, but i have a problem.
If I just dont understand some concept of your app, please explain me them.
I patterned my solution on OrGate and AndGate. As far as i know imputs of each gate are taken from top and bottom square. But the state of wire is not read correctly. I added console log for debugging, please see example below:

export default class XorGate extends Component {
   constructor(x, y, options={}) {
     super(x, y, {
       char: '⊕',
       name: 'xor',
       category: 'control',
       conductDirections: [Direction.LEFT, Direction.RIGHT],
       receiveDirections: [Direction.UP, Direction.DOWN]
     });
   }
 
   simulate(from, board) {
     const downState = this.board.get(this.x, this.y + 1).on;
     const upState = this.board.get(this.x, this.y - 1).on;
     const condition = (this.board.get(this.x, this.y + 1).on ^
     this.board.get(this.x, this.y - 1).on) === 1;
     console.log('up: ' + upState + ' XOR down: ' + downState + ' = ' + condition);
     if (condition) {
       super.simulate(from, board);
     }
   }
}

So, i log to console two imputs and result of xor operation, but the output is unexpected:
The top input is false, but it is actualy true (It is green, isnt it?).
bug

@zac-garby
Copy link
Owner Author

zac-garby commented Oct 22, 2017

I haven't looked at this project for a long time now, but I seem to remember the implementations for logic gates being a bit hacky.

One thing I've noticed in your code is your use of the ^ operator, which I'm pretty sure is actually a numeric operator (i.e. 0b1010 ^ 0b0110 == 0b1100), so that might be a problem.

Not that it would be a problem, but I also noticed you define downState and upState, only to not use them when you compute the condition on the next line.

Here's what you might want to try (untested)

const down = this.board.get(this.x, this.y + 1).on;
const up = this.board.get(this.x, this.y + 1).on;

if ((up || down) && !(up && down)) {
    super.simulate(from, board);
}

EDIT: @pszczolas - forgot to mention you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants