Coder Social home page Coder Social logo

Comments (9)

calcitem avatar calcitem commented on August 27, 2024

乌龙,为 mod12 bug 造成。已修复。

from chaosclock.

ejmoog avatar ejmoog commented on August 27, 2024

在選擇行動時,需要對pieces的hand和running合併,這是當前棋手的可選行動。我不知道改成數組之後,能否正準獲取它們的長度,如果可以,就沒問題。

from chaosclock.

calcitem avatar calcitem commented on August 27, 2024

如果不取长度可以吗?12+12一共24个字节,前面12是棋盘,后面12个是手中的棋子,依次遍历到底,手中没这个棋的,对应位置就是0。这样不用管手中有几个棋子。因为循环依次遍历,在数组长度不大的情况下,说不定比vector操作还节省计算量,并且也方便利用CPU Cache做prefetch。vector的话,计算期间分支跳转多,几乎做不了prefetch。

from chaosclock.

calcitem avatar calcitem commented on August 27, 2024

vector为啥操作开销大呢,是因为涉及内存分配,销毁,空间不够的情况下的再分配,还有数据的搬移等等,开销也不小,说不定还不如数组遍历快。

from chaosclock.

calcitem avatar calcitem commented on August 27, 2024

Piece 内部有多个成员数组,和Piece内部成员不是数组,而是由多个Piece组成数组,哪种结构更好?

from chaosclock.

ejmoog avatar ejmoog commented on August 27, 2024

Piece 内部有多个成员数组,和Piece内部成员不是数组,而是由多个Piece组成数组,哪种结构更好?

我不太明白,你能寫個示例出來嗎?

我感覺c++還提供了不少數據類型,這裏確實不宜用vector。因為「hand、stick、free、dead、stop、stock」這些都確定只有兩個int[6],而vector是變長的。

但我不知道還有哪種數據類型可以用,我只知道vector能用…

from chaosclock.

ejmoog avatar ejmoog commented on August 27, 2024

hand、stick、free、dead、stop、stock都應該做成二維int數組,一維長度是6,二維長度是2個。

run是一維數組,長度是12。

from chaosclock.

ejmoog avatar ejmoog commented on August 27, 2024

沒有值則是0。有值則是1~12。

from chaosclock.

calcitem avatar calcitem commented on August 27, 2024

可以先优化成数组,OK后进一步优化为bit位运算。

from chaosclock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.